How can I remove default headers that cURL sends?
Solution 1
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
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
.
Jilles van Gurp
Senior backend engineer and Elasticsearch specialist that sometimes doubles as a CTO or product architect. I've also built stuff with the Stellar blockchain and can help companies with any of these things. I can work with many tech stacks. Currently I favor Kotlin (with Spring Boot, Ktor, or similar) on the backend but I've also used python, go, node.js (with typescript), and a few other tech stacks. I also maintain the Kotlin OSS clients for Elasticsearch and Stellar.
Updated on March 24, 2021Comments
-
Jilles van Gurp about 3 years
Curl by default adds headers such as
Content-type
andUser-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 postingapplication/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