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://domain.com' -d '{...}'

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

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)


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

curl 172.20.11.100:8080/healthz -v -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 the -v option as shown above.

链接地址: http://www.djcxy.com/p/8626.html

上一篇: 如何在休息客户端使用spring @RequestBody发送post请求

下一篇: 我如何删除卷曲发送的默认标题