IPhone Development: How to Implement HTTPS Connection?

I am working on an iPhone project that needs to connect to an IIS server over HTTPS or SSL. Can anyone tell me how to implement HTTPS connection in iPhone? Any advice would be appreciated.

Thanks in advance.

+2


a source to share


4 answers


Ben Copsey ASIHTTPRequest

framework makes it easy to issue web requests over SSL.

Modify the example site a bit:



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

      

+2


a source


Just use NSURLConnection with NSURLRequest pointing to NUSUL with https protocol, exactly the same:

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 check out the documentation for the URL loading system in Cocoa.

0


a source


Jason don't forget to implement the connection: canAuthenticateAgainsProtectionSpace and the connection: didReceiveAuthenticationChallenge to make sure you handle the server authentication and client authentication issues:

Remember this post to help you with this https://devforums.apple.com/message/143091#143091

0


a source


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

0


a source







All Articles