在UIWebView中加载HTTPS url

问题描述:

我开始进行iPhone编程,并遇到很大的问题,无法解决。在UIWebView中加载HTTPS url

所以,我有一个UIWebview,我可以加载HTTP网址没有问题:

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

它的工作,我的页面加载在我的UIWebView,但是当我更换:

urlAdress = @"http://servername"; 

urlAdress = @"https://servername"; 

我有空白屏幕。

我读了它的正常,但有没有简单的方法来在我的webview中加载https url?
我读了ASIHTTPRequest,但我没有达到实施它。

我只是想加载HTTPS URL

+0

会发生什么事,如果你加载'的https:// servername'在Safari? – deanWombourne 2011-06-10 14:05:09

+0

在safari中我可以加载“http:// servername”和“https:// servername” – Borneto 2011-06-10 14:07:55

+1

这是否带有自签名证书? – Jim 2011-06-10 16:53:03

试试这个:

- (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]; 
} 
+1

我只是将它添加到包含UIWebView的UIViewController?我不太确定该怎么做。 – powerj1984 2012-08-31 17:35:11

+1

这两个方法是[NSURLConnectionDelegate](https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html)协议的一部分,因此您可以将它们放入任何文件充当您NSURLConnection的代表。 – 2012-10-12 14:10:58

+0

我也在使用自己分配的证书,它与上面的实现一起工作。 – m4n1c 2013-04-03 06:01:32