Search code examples
curlhttp-headerscontent-typex-www-form-urlencoded

How can I remove default headers that cURL sends?


Curl by default adds headers such as Content-type and User-agent. Normally that is a good thing but I'm trying to test what our server does when those headers are missing.

My problem is with the Content-type header. If it is missing, the server correctly assumes the user sent JSON. However, curl actually adds the missing header and incorrectly assumes that the content I am posting application/x-www-form-urlencoded. It also sends an Accept header of */*.

I suppose that is nice default behavior but I basically would like it to not send headers I did not specify. Is there an option for that?

curl -v -X POST 'https://example.com' -d '{...}'

> User-Agent: curl/7.37.1
> Host: example.com
> Accept: */*
> Content-Length: 299
> Content-Type: application/x-www-form-urlencoded

Solution

  • Use -H flag with the header you want to remove and no content after the :

    -H, --header LINE   Custom header to pass to server (H)
    

    Sample

    -H 'User-Agent:'
    

    This will make the request without the User-Agent header (instead of sending it with an empty value)