首页 > 文章列表 > python如何使用requests检查请求

python如何使用requests检查请求

Python requests
494 2022-08-07

1、说明

当发出请求时,requests 库会在将请求实际发送到目标服务器之前准备该请求。 请求准备包括像验证头信息和序列化JSON内容等。

2、实例

可以通过访问 .request 来查看 PreparedRequest:

>>> response = requests.post('https://httpbin.org/post', json={'key':'value'})
>>> response.request.headers['Content-Type']
'application/json'
>>> response.request.url
'https://httpbin.org/post'
>>> response.request.body
b'{"key": "value"}'

通过检查 PreparedRequest,可以访问有关正在进行的请求的各种信息,例如有效负载,URL,头信息,身份验证等。

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。