Search code examples
curlfilesizestatcontent-length

File Size VS Curl Content-Length


I would like to have the same size of the automatic Content-Length header.

I will explain with examples :

When I do this : echo "testing" | wc -c // The result is : 8

or

When I do this : stat -c '%s' "test.txt" (on a file who contain the word : "testing") // The result is 8

BUT

When I do this : curl -v -d "testing" http://www.google.fr // The result is Content-Length: 7

OR

When I do this : curl -v -d "@test.txt" http://www.google.fr // The result is Content-Length: 7

Why ?

How can I have the same size ?

Thank you for your help.

Ben


Solution

  • echo adds a newline character, so 7 + newline = 8

    The curl -d option sends only the quoted characters.

    To suppress the newline use `-n', this will give 7:

    echo -n "testing" | wc -c
    

    or use printf instead:

    printf "testing" | wc -c