获取发送的curl请求的大小


9

有没有办法以curl编程方式获取请求的大小?

例如,如果我这样做

curl 'http://www.example.com/url' \
-H 'Cookie: cookie=cookiedata;' \
-H 'X-CSRFToken: csrffake' \
--data 'example=moredata \
--compressed

我想知道我发送的请求有多大?


标头请求大小?
Braiam 2014年

@Braiam生成的请求的大小(不包括以太网/ ip层)。因此,我认为标头+数据。
polym 2014年

Answers:


12

好了,经过一番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.

这意味着-w '%{size_request} %{size_upload}'在请求之后添加a ,然后在输出中添加结果数,将为您提供总的请求大小。


1
注意:如果您使用HTTP,则不包括TLS开销。
dcoles
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.