Detect whether UIWebView needs to use HTTP or HTTPS

£可爱£侵袭症+ 提交于 2020-01-02 21:54:08

问题


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!


回答1:


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. 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.

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.



来源:https://stackoverflow.com/questions/7211991/detect-whether-uiwebview-needs-to-use-http-or-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!