【问题标题】:Load HTTPS url in a UIWebView在 UIWebView 中加载 HTTPS url
【发布时间】:2011-09-12 12:55:48
【问题描述】:

我开始 iPhone 编程,但我遇到了无法解决的大问题。

所以,我有一个UIWebview,我可以毫无问题地加载 HTTP url:

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。

【问题讨论】:

  • 如果你在 Safari 中加载 https://servername 会发生什么?
  • 在 safari 中我可以同时加载 "http://servername" 和 "https://servername"
  • 这是带有自签名证书的吗?
  • 没错,它是自签名证书!

标签: ios url https uiwebview asihttprequest


【解决方案1】:

试试这个:

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

【讨论】:

  • 我只是将它添加到包含 UIWebView 的 UIViewController 中吗?我不太确定该怎么处理。
  • 这两个方法是NSURLConnectionDelegate 协议的一部分,因此您可以将它们放在充当 NSURLConnection 代理的任何文件中。
  • 我也使用了自分配证书,它适用于上述实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-04
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多