抓包安卓 app,发现实际请求的 header 是
Content-Type: application/x-www-form-urlencoded; charset= token: sasasasasasasasasasas Host: ********:8443 Connection: Keep-Alive
用 requests 模拟,添加上述 header 以后,发现实际发送的请求经过 requests 处理,header 增加了几项(带*的)
*User-Agent: python-requests/2.19.1 *Accept-Encoding: gzip, deflate *Accept: */* Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded; charset= Host: *******:8443 *Content-Length: 0 token: sasasasasasasasasasas
求助怎么完全自定义 requests 的 header,或者删除 header 中的某些项,文档中没找见....
1 julyclyde 2018-08-18 14:59:19 +08:00 不能删除 你可以覆盖掉它 |
2 alvin666 OP @julyclyde 是可以覆盖,比如模拟浏览器操作的时候,header 换成 Chrome,然而这个是 app 的请求,万一服务端来个 header 过滤就 gg... |
![]() | 3 kmahyyg 2018-08-18 15:06:10 +08:00 via iPad ```python custom_headers={"user-agent": "", ......} r = requests.get(url, headers=custom_headers} ``` 请参考文档 |
4 alvin666 OP @kmahyyg 我就是这么做的,但是只能覆盖,如果值空白,发送的请求里面也有,不能删除已有的 cookie,文档里面没有提到我才来问的,谢谢 |
5 stamaimer 2018-08-18 15:14:19 +08:00 via iPhone None |
![]() | 7 holajamc 2018-08-18 15:21:29 +08:00 ![]() @alvin666 @stamaimer 的意思是这样 import requests proxies = { "http": "http://127.0.0.1:8888", "https": "http://127.0.0.1:8888", } headers = {'User-Agent': None} requests.get("http://example.org", headers=headers, proxies=proxies) |
![]() | 8 Xiaobaixiao 2018-08-18 15:29:12 +08:00 ![]() |
9 alvin666 OP @Xiaobaixiao @holajamc 谢谢!最近被墙的厉害,没仔细在谷歌上面找,感谢! |