开发者

iPhone development: How to implement HTTPS connection?

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.


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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜