获取发送的 curl 请求的大小

pol*_*lym 10 curl

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

例如,如果我这样做

curl 'http://www.example.com/url' \
-H 'Cookie: cookie=cookiedata;' \
-H 'X-CSRFToken: csrffake' \
--data 'example=moredata \
--compressed
Run Code Online (Sandbox Code Playgroud)

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

pol*_*lym 17

好吧,经过一番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.
Run Code Online (Sandbox Code Playgroud)

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

  • 注意:如果您使用 HTTP,这不包括 TLS 开销。 (2认同)