<分区>
我们有一个使用 UIWebView 来显示内容的 iOS 应用程序。我们用如下代码加载数据:
NSURL *url = [NSURL URLWithString:myURLString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView setDelegate:self];
[_webView loadRequest:request];
这过去适用于 HTTP 请求,但现在我们对具有自签名 SSL 证书的服务器使用 HTTPS。运行上述代码时,将调用 webView:didFailLoadWithError:
委托(delegate)方法,并出现以下错误:
The certificate for this server is invalid. You might be connecting to a server that is pretending to be "blah.blah.blah.com" which could put your confidential information at risk."
我只想忽略无效证书并继续请求,就像在 Mobile Safari 中所做的那样。
我已经了解了如何在使用 NSURLConnection
时解决此问题(例如,请参见 HTTPS request on old iphone 3g),但是使用 UIWebView
可以做什么?
我想我可以重新编写代码,使其使用 NSURLConnection
发出请求,然后通过调用其 loadHTMLString:baseURL:
将结果放入 Web View 中方法,但是当页面包含图像、CSS、JavaScript 等时,这会变得复杂。有没有更简单的方法?