如何删除curl发送的默认标头 [英] How can I remove default headers that curl sends
问题描述
默认情况下,Curl添加标头,例如Content-type和User-agent。通常,这是一件好事,但当这些标头丢失时,我正在尝试测试服务器的工作。我的问题是内容类型标题。如果丢失,则服务器正确假定用户已发送json。但是,curl实际上会添加缺少的标题,并错误地假定我发布的内容是application / x-www-form-urlencoded。它还发送 / 的Accept标头。我想这是不错的默认行为,但我基本上希望它不发送未指定的标头。
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
推荐答案
对要删除的标头使用 -H
标志,在之后没有任何内容:
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)
样本
-H 'User-Agent:'
这将使请求 无 $ c> User-Agent 标头(而不是发送带有空值的标头)
This will make the request without the User-Agent
header (instead of sending it with an empty value)
这篇关于如何删除curl发送的默认标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!