指定HTTP协议会有所不同吗? [英] Does specifying HTTP protocol makes a difference?

查看:125
本文介绍了指定HTTP协议会有所不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个bs4对象之间有区别吗?



 来自 urllib2  import  urlopen,请求
来自 bs4 import BeautifulSoup

req1 =请求( https:// stackoverflow。 com / HTTPS
html1 = urlopen(req1).read ()

req2 =请求( http://stackoverflow.com/ HTTP
html2 = urlopen(req2).read()

bsObj1 = BeautifulSoup(html1, html.parser
bsObj2 = BeautifulSoup(html2, html.parser



你真的需要指定一个HTTP协议吗?



我是什么尝试过:



我试过比较那两个,似乎没有工作

解决方案

< blockquote>第一个将发出安全请求。



第二个会发出一个不安全的请求,自动重定向到安全版本,但仅限于因为StackOverflow已经配置了他们的网站要做到这一点。



使用第一个版本将避免额外请求,以及通过不安全连接发送数据的任何可能性。它还将删除您的代码库是否透明地处理重定向的任何问题。



换句话说:指定HTTP协议(而不是HTTPS)保存您输入一个字符,代价是在您的应用程序中引入潜在的安全问题。


Is there a difference between those two bs4 objects?

from urllib2 import urlopen, Request
from bs4 import BeautifulSoup

req1 = Request("https://stackoverflow.com/")  # HTTPS
html1 = urlopen(req1).read()

req2 = Request("http://stackoverflow.com/")  # HTTP
html2 = urlopen(req2).read()

bsObj1 = BeautifulSoup(html1, "html.parser")
bsObj2 = BeautifulSoup(html2, "html.parser")


Do you really need to specify an HTTP protocol?

What I have tried:

I tried comparing those two, didn't seem to work

解决方案

The first one will make a secure request.

The second one will make an insecure request, which should automatically be redirected to the secure version, but only because StackOverflow have configured their site to do that.

Using the first version will avoid the extra request, and any possibility of data being sent over an insecure connection. It will also remove any question of whether your code library handles the redirection transparently.

In other words: specifying the HTTP protocol (rather than HTTPS) saves you typing one character, at the expense of introducing a potential security problem into your application.


这篇关于指定HTTP协议会有所不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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