如何通过Python请求发送请求的完整大小(我没有要求回复)
我应该只添加body
(如果适用)和headers
的长度吗?
对于请求元素,还有什么需要考虑的事情吗?
这适用于我希望计算其大小的任何请求已发送(GET,POST,DELETE)。
答案 0 :(得分:0)
Short answer - size of request is sum of mainly size of method, URL, headers and body (if apply) so in approximation it will be:
import requests
response = requests.get('https://httpbin.org/get')
method_len = len(response.request.method)
url_len = len(response.request.url)
headers_len = len('\r\n'.join('{}{}'.format(k, v) for k, v in response.request.headers.items()))
body_len = len(response.request.body if response.request.body else [])
print(f'Request size {method_len + url_len + headers_len + body_len}')
If anything more apply please post comment.
Resources:
RFC documentation https://tools.ietf.org/html/rfc7230#section-3
中反转用户名 System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
库存储库成员响应:
https://github.com/requests/requests/issues/4694
@Stack对这个问题的评论,他提到Python requests - print entire http request (raw)?
有关URI的问题:Is URL a part of request size?