检测UIWebView是否需要使用HTTP或HTTPS [英] Detect whether UIWebView needs to use HTTP or HTTPS

查看:57
本文介绍了检测UIWebView是否需要使用HTTP或HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测UIWebView中的网页是否需要使用HTTP或HTTPS?我有一个地址栏,用户可以在其中输入"www.apple.com",然后将其转换为带有http://的NSString.但是,如果Apple.com需要HTTPS,将如何处理?我到底该怎么办?感谢您的帮助!

How do I detect whether a web page in a UIWebView needs to use HTTP or HTTPS? I have an address bar where the user can type in "www.apple.com" and then I convert this to a NSString with http:// in front of it. If Apple.com requires HTTPS though, how would this be handled? What exactly should I do? Thanks for your help!

推荐答案

在大多数情况下,需要HTTPS的网站被设置为自动重定向到正确的SSL端口.通常是这样的:

In most cases, a web site that requires HTTPS is set up to automatically redirect to the correct SSL port. In generally goes like this:

  1. 在网络浏览器中输入URL http://www.mysite.com/.由于未指定端口,因此它将尝试将默认端口80用于HTTP.
  2. 站点在端口80上收到请求,并确定您需要使用SSL,因此它将重定向响应发送回浏览器.重定向响应通常会告诉您的浏览器在标准HTTPS端口(443)上使用HTTPS再试一次.
  3. 您的浏览器将请求重新发起到HTTPS端口.
  1. Enter the URL http://www.mysite.com/ in your web browser. Because there is no port specified, it attempts to use the default port of 80 for HTTP.
  2. The site receives the request on port 80 and determines that you need to be using SSL, so it sends a redirect response back to the browser. That redirect response usually tells your browser to try again using HTTPS on the standard HTTPS port (443).
  3. Your browser re-initiates the request to the HTTPS port.

因此,在大多数情况下,您不需要知道是否需要HTTPS.只需使用http进入该网站.如果需要HTTPS,它将几乎总是自动将您重定向到那里.

So, in the vast majority of cases, you don't need to know whether or not HTTPS is required or not. Just go to the site using http. If it requires HTTPS it will almost always redirect you there automatically.

这篇关于检测UIWebView是否需要使用HTTP或HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆