xcode 在 UIWebView 中加载 HTTPS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12659264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:49:58  来源:igfitidea点击:

Loading HTTPS in UIWebView

iphonexcodessluiwebviewssl-certificate

提问by Annabel

I have a page with UIWebView, it was working well until recently some of the redirection changed, with the URL from HTTP to HTTPS. The page could not be displayed.

我有一个带有 UIWebView 的页面,它运行良好,直到最近一些重定向发生了变化,URL 从 HTTP 变为 HTTPS。无法显示页面。

Error logged:

错误记录:

Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid.

Now, I wish to bypass all the cert checks and allow all the certs. Tried using this How to use NSURLConnection to connect with SSL for an untrusted cert?but the error still comes out. Help, anyone? Thanks!

现在,我希望绕过所有证书检查并允许所有证书。尝试使用此如何使用 NSURLConnection 连接 SSL 以获得不受信任的证书?但错误仍然出现。帮助,有人吗?谢谢!

采纳答案by Annabel

Actually found a solution here: UIWebView to view self signed websites (No private api, not NSURLConnection) - is it possible?

实际上在这里找到了一个解决方案:UIWebView 查看自签名网站(没有私有 api,不是 NSURLConnection) - 这可能吗?

What it actually does is to intercept the UIWebView to launch a NSURLConnection to allow the server to be authenticated, therefore then continue the connection using UIWebView, and cancels out the NSURLConnection. Reason so is because after authorising the server once, the rest of the continuous connection would not be blocked. Hope i'm clear. :)

它实际上做的是拦截 UIWebView 以启动 NSURLConnection 以允许服务器进行身份验证,因此然后使用 UIWebView 继续连接,并取消 NSURLConnection。之所以如此,是因为对服务器进行一次授权后,其余的连续连接不会被阻塞。希望我很清楚。:)