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

时间:2010-05-11 09:14:24

标签: iphone ssl https

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

提前谢谢你。

4 个答案:

答案 0 :(得分:2)

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);
}

答案 1 :(得分:0)

只需使用NSURLConnection,NSURLRequest指向带有https协议的NUSUL,就像那样:

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 loading system的文档。

答案 2 :(得分:0)

Jason不要忘记实施连接:canAuthenticateAgainsProtectionSpace connection:didReceiveAuthenticationChallenge ,以确保您正在处理服务器身份验证和客户端身份验证的挑战:< / p>

查看此帖子,可以帮助您完成此https://devforums.apple.com/message/143091#143091

答案 3 :(得分:0)

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