How can I remove default headers that cURL sends?

CurlHttp HeadersContent TypeX Www-Form-Urlencoded

Curl Problem Overview


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: domain.com
> Accept: */*
> Content-Length: 299
> Content-Type: application/x-www-form-urlencoded

Curl Solutions


Solution 1 - Curl

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)

Solution 2 - Curl

Seems like curl sends 3 headers. To do a request without them you can append the arguments:

-H 'User-Agent:' -H 'Accept:' -H 'Host:'

+1 to @cmlndz answer as he explains how to remove a single header.

You can check which headers are actually sent by adding -v.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJilles van GurpView Question on Stackoverflow
Solution 1 - CurlcmlndzView Answer on Stackoverflow
Solution 2 - CurlakostadinovView Answer on Stackoverflow