Is there a way to get the size of a curl request programmatically?

E.g. if I do

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

I want to know how big my sent request is?

  • The header request size? – Braiam Aug 17 '14 at 15:40
  • @Braiam The size of the resulting request (excluding ethernet/ip layers). So header + data I think. – polym Aug 17 '14 at 15:45

Ok after some man curl digging, I think I've found out the answer, though I'm not 100% sure about it's validity:

 -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.

That means adding a -w '%{size_request} %{size_upload}' and then adding the resulting numbers in the output after the request will give you the request size in total.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.