7

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.

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Borneto
  • 71
  • 1
  • 1
  • 2

1 Answers1

6

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];
}
Niko
  • 2,543
  • 1
  • 24
  • 29
  • 1
    Do I just add this to the UIViewController containing the UIWebView? I'm not quite sure what to do with this. – powerj1984 Aug 31 '12 at 17:35
  • 1
    These two methods are part of the [NSURLConnectionDelegate](https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html) protocol, so you put them in whichever file is acting as the delegate for your NSURLConnection. –  Oct 12 '12 at 14:10
  • i was also using a self assigned certificate and it worked with the above implementation. – m4n1c Apr 03 '13 at 06:01