iPhone开发:如何实现HTTPS连接?

发布于 2024-08-31 17:01:34 字数 109 浏览 2 评论 0原文

我正在开发一个 iPhone 项目,需要通过 HTTPS 或 SSL 协议连接到 IIS 服务器。谁能告诉我如何在 iPhone 中实现 HTTPS 连接?任何建议将不胜感激。

先感谢您。

I am working on an iPhone project which need to connect to the IIS server over HTTPS or SSL protocol. Can anyone tell me how to implement HTTPS connection in iPhone? Any advice would be appreciate.

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阳光下的泡沫是彩色的 2024-09-07 17:01:34

Ben Copsey 的 ASIHTTPRequest 框架使通过 SSL 发出 Web 请求变得非常简单。

稍微修改一下网站的例子:

NSURL *url = [NSURL URLWithString:@"https://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
    NSString *response = [request responseString];
    NSLog (@"%@", response);
}

Ben Copsey's ASIHTTPRequest framework makes it trivially easy to issue web requests over SSL.

Modifying the site's example slightly:

NSURL *url = [NSURL URLWithString:@"https://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
    NSString *response = [request responseString];
    NSLog (@"%@", response);
}
︶ ̄淡然 2024-09-07 17:01:34

只需将 NSURLConnection 与指向带有 https 协议的 NUSUL 的 NSURLRequest 一起使用,就像这样:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://mySecureServer.net"]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!error) {
    //do something with response & data
}

但我建议您查看 Cocoa 中的 URL 加载系统

Just use NSURLConnection with an NSURLRequest pointing to an NUSUL with https protocol, just like that:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://mySecureServer.net"]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!error) {
    //do something with response & data
}

But I suggest you have a look at the documentation of the URL loading system in Cocoa.

贪恋 2024-09-07 17:01:34

Jason 不要忘记实现 connection:canAuthenticateAgainsProtectionSpaceconnection:didReceiveAuthenticationChallenge 以确保您正在处理服务器身份验证和客户端身份验证的挑战:

查看这篇文章这将帮助您https://devforums.apple.com/message/143091#143091< /a>

Jason don't forget to implement the connection:canAuthenticateAgainsProtectionSpace and connection:didReceiveAuthenticationChallenge to make sure you're handling the challenges for the Server authentication and Client Authentication:

check out this post that will help you with this https://devforums.apple.com/message/143091#143091

月下凄凉 2024-09-07 17:01:34

您可能没有公共证书。用firefox/safari/chrome访问https资源能不报错吗?如果不是 - 这就是问题,而不是你的代码。

You probably don't have a public certificate. Can you access the https resource with firefox/safari/chrome without an error? if not - that's the problem, not your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文