使用Python请求库获取发送和接收数据的时间戳

2024-03-28 18:07:49 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python的requests库,是否有可能获得接收和发送数据的确切时间戳,例如报头或有效负载数据?你知道吗

示例:

import requests

url     = 'http://mytest.url'
headers = {'User-Agent': 'My Agent'}
payload = 'Hello World'

response = requests.post(url, payload, headers)

print response

输出(注意,报头和有效负载数据可能有不同的接收时间戳!)地址:

2019/10/09 13:00.05.12345 >> POST http://mytest.url HTTP/1.1
2019/10/09 13:00.05.67890 >> User-Agent: My Agent
2019/10/09 13:00.06.12345 >> Hello World
2019/10/09 13:00.10.12345 << HTTP/1.1 200 OK
2019/10/09 13:00.11.12345 << Connection: Keep Alive
2019/10/09 13:00.12.12345 << Hello My Agent

问候, 史蒂夫


Tags: 数据httpurlhelloworldresponsemy时间