views:

608

answers:

4

Hi all,

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.

A: 

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);
}
Alex Reynolds
A: 

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.

stigi
Hi stigi, Thanks for your helping. And I have read the documentation of the URL loading system in Cocoa. But I'm still struggling with the HTTPS issue. I have changed my code like the above. But the clause "!error" are always not true which indicates that there must be some error. Is there anything I need to do on the server? And how to setup the server? By the way, the server in this case is write using ASP running on IIS. Looking forward for your help! ThanksJason
Jason
A: 

Hi Alex,

Thanks for your guide. I have tried like you mentioned above. But I got the Error:

Error Domain=ASIHTTPRequestErrorDomain Code=1 UserInfo=0xeb3ce0 "A connection failure occurred: SSL problem (possibly a bad/expired/self-signed certificate)"

Can you give me any more details on how to solve this issue?

Thanks Jason

Jason
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

emmanuel.aquino