繁体   English   中英

如何在UIWebView上加载网页(使用自签名证书的Https)?

[英]How to load a webpage (Https using a self signed certificate) on the UIWebView?

如何在UIWebView(iOS)上加载网页(使用自签名证书的Https)? 我尝试使用NSURLConnection,并且能够将NSMutableData加载到UIwebView。 但是在这种情况下,我无法看到该页面中的图像。

[yourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"yourUrlGoesHere"]]];

关于证书部分,如果您的URL可在Safari中打开,它将在Web视图中打开。


更新评论

试试下面

NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"yourUrlGoesHere"]];
NSURLConnection *urlConnection=[NSURLConnection connectionWithRequest:req delegate:self];
[yourWebView loadRequest:req];

并在您的课程中实现以下委托方法,

#pragma mark - NSURLConnection Delegate Methods
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

客户端大部分时间无法验证自签名证书,这就是客户端无法加载数据的原因,因为它无法从服务器进行验证。

证书使用域进行自我验证,因此在开发环境中有点困难。

有一个为本地环境证书创建的工具,我不确定它在内部如何工作,我最好是在您的环境中添加另一个CA文件。

您可能要检查mkcert ,使用好解决方法非常容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM