iOS 5 NSURL连接到HTTPS服务器
我已经搜索了几个小时有关 NSURLConnection 委托/方法的信息,这些委托/方法允许我用来连接到任何 HTTPS 服务器。即使我在这个网站上搜索,我也找到了答案,但这些答案对我不起作用。
如果你们需要的话,我会上传代码链接。但我更喜欢连接到任何 HTTPS 服务器
的简单 UIWebView
的教程/示例代码/源代码。我将从那里开始。
提前致谢。
I have searched for hours regarding the NSURLConnection
delegates/methods that allows me to use to connect to any HTTPS servers. Even I searched on this site and I found answers, answers which didn't work for me.
I will upload the code link if any of you want me to. But I would prefer a tutorial / sample codes / source code of a simple UIWebView
connecting to any HTTPS Servers
. And I will take it from there.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论您连接到 HTTPS 还是 HTTP 站点,对于 NSURLConnection 和 UIWebView 控件都应该是完全透明的。您可能需要做的唯一一件事是,如果服务器站点证书是自签名或不可验证的证书,请添加代码以绕过浏览器获得的身份验证质询。 (即相当于证书由未知颁发机构签名并且您是否要接受的消息)。
只需使用 @"https://www.myhttpsite.com/" URL,它的工作方式应该与普通 HTTP URL 相同。
要绕过无法识别的证书签名者的安全问题,对于 NSURLConnection,请将以下内容添加到您的委托方法中:
在 iOS4.3 之前,您需要做一些不同的事情,您可以向实现安全绕过的 URLRequest 类添加一个类别来自无法识别的主机的证书。
请注意,任何忽略证书未由公认的权威机构签名的解决方案都要小心,因为您在执行此操作时会打开潜在的安全漏洞,但至少对于具有自我/内部的测试服务器进行测试通常是必要的上面签署了证书。
要在 Web 视图中打开 URL 连接:
Whether you are connecting to a HTTPS or HTTP site should be completely transparent both for NSURLConnection and for UIWebView controls. The only thing you may need to do is, if the server sites certificate is a self-signed or non-verifiable certificate, add code to bypass the authentication challenge that the browser gets. (i.e. the equivalent of the message that the certificate is signed by an unknown authority and do you want to accept it).
Just use a @"https://www.myhttpsite.com/" URL and it should work the same way as normal HTTP urls.
To bypass the security issue of an unrecognised certificate signer, for an NSURLConnection, add the following to your delegate methods:
In pre iOS4.3 you need to do something a bit different, you can add a category to the URLRequest class that implements security bypass for certificates from an unrecognised host.
Note be careful with any solution that ignores that a certificate isn't signed by a recognised authority as you are opening up a potential security hole when doing it, but it often is necessary at least for testing against a test server that has self/internally signed certificate on it.
To open a URL connection in a web view:
好的,我找到了答案。也感谢 gamozzii 对我的帮助。我根据您的代码进行了搜索:)
在 UIWebView 中加载 HTTPS url
这对我有用。我还尝试了
https://www.google.com
等链接Ok, I found my answer. Thanks gamozzii for assisting me as well. I did a search based on your codes :)
Load HTTPS url in a UIWebView
This works for me. I also tried links like
https://www.google.com