【发布时间】:2020-09-12 12:06:27
【问题描述】:
我想按照我写下来的完全相同的顺序来做一个带有标题的请求。 但是使用 Burp 我发现无论我如何在代码中编写它,它似乎都会以另一种方式自行对标头进行排序。
这是我的标题顺序:
headers = {
'Host': 'localhost',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'de-DE',
'Accept-Encoding': 'gzip, deflate',
'Content-type': 'application/json',
'Content-Length': '31',
'Referer': 'https://localhost',
'Connection': 'close',
'Origin': 'https://localhost',
}
这是 Burp 截获的请求中的顺序:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Accept-Encoding: gzip, deflate
Accept: application/json, text/plain, */*
Connection: close
Host: localhost
Accept-Language: de-DE
Content-type: application/json
Content-Length: 32
Referer: https://localhost
Origin: https://localhost
版本和操作系统:
Windows 10
python3 --version
Python 3.8.6rc1
pip freeze |findstr requests
requests==2.24.0
【问题讨论】:
-
This 是一个类似的问题。
-
是的,但 headers = OrderedDict() 不会改变顺序。
-
这不是你想要的吗?
-
对不起,我表达错了。这行代码什么都不做。带和不带的顺序是相同的“错误”
-
嗯,很奇怪。我需要试验你的代码来理解你的问题。明天恢复。
标签: python-3.x python-requests http-headers