Load HTTPS url in a UIWebView

Borneto picture Borneto · Jun 10, 2011 · Viewed 14.1k times · Source

I begin iPhone programming and I have big problem I cant resolve.

So, I have a UIWebview, I can load HTTP url without problems :

NSString urlAdress;
urlAdress = @"http://servername";
NSURL *url = [NSURL URLWithString:urlAdress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

Its work, my page is load in my UIwebView, but when I replace :

urlAdress = @"http://servername";

by

urlAdress = @"https://servername";

I have blank screen.

I read its normal, but is there easy method to load https url in my webview ?
I read about ASIHTTPRequest but I didnt arrive to implement it.

I just want to load HTTPS URL.

Answer

Niko picture Niko · Dec 13, 2011

Try this :

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return YES;
}


- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}