有没有办法以编程方式获取请求的大小curl
?
例如,如果我这样做
curl 'http://www.example.com/url' \
-H 'Cookie: cookie=cookiedata;' \
-H 'X-CSRFToken: csrffake' \
--data 'example=moredata \
--compressed
我想知道我发送的请求有多大?
答案1
好吧,经过一番man curl
挖掘,我想我已经找到了答案,尽管我不能 100% 确定它的有效性:
-w, --write-out <format> Defines what to display on stdout after a completed and successful operation. [...] The variables present in the output format will be substituted by the value or text that curl thinks fit, as described below. All variables are specified as %{variable_name} and to output a normal % you just write them as %%. [...] size_request The total amount of bytes that were sent in the HTTP request. size_upload The total amount of bytes that were uploaded.
这意味着添加 a -w '%{size_request} %{size_upload}'
,然后在请求后的输出中添加结果数字将为您提供请求的总大小。