有很多问题要问:我可以UIWebView查看自签名的HTTPS网站吗?
答案总是涉及:
NSURLRequest:allowsAnyHTTPSCertificateForHostNSURLConnection代替和委托canAuthenticateAgainstProtectionSpace等对我来说,这些都不行.
(1) - 表示我无法成功提交到应用商店.
(2) - 使用NSURLConnection意味着在加载初始HTML页面后必须从服务器获取的CSS,图像和其他内容.
有谁知道如何使用UIWebView查看自签名的https网页,这不涉及上述两种方法?
或者 - 如果使用NSURLConnectioncan实际上可以用来渲染一个完整的CSS,图像和其他所有的网页 - 这将是伟大的!
干杯,
拉伸.
我正在尝试将具有自签名证书的HTTPS网页加载到UIWebView中.使用类似这一个或这个的提示,它可以在iOS 6下运行.同样在iOS 7中不起作用.
根据链接到Stack Overflow的问题,我还使用NSURLConnection首先尝试通过自签名证书 - 这一切都在尝试加载UIWebView中的URL之前.
在iOS 7中尝试相同时,我收到以下错误:
2014-02-12 16:00:08.367 WebView [24176:5307] NSURLConnection/CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)
2014-02-12 16:00:08.370 WebView [24176:70b]发生SSL错误,无法与服务器建立安全连接.
是否有解决方案可以在iOS 7中使用它?目前我正在使用第一个例子.
我正在访问一个Web服务并在尝试连接时收到此错误(Web服务是XMLRPC,我使用wordpress xmlrpc源代码请求和处理repsonse):
错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能正在连接到假装为" ** .org" 的服务器,这可能会使您的机密信息面临风险."
WebService的人说要忽略证书验证部分,所以如果有人知道怎么做,那将对我有很大的帮助.
在一些建议之后我使用了下面的NSURLConnection委托,stil同样的错误
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
if ([trustedHosts containsObject:challenge.protectionSpace.host])
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
Run Code Online (Sandbox Code Playgroud)