使用curl发布数据,但没有Content-Type标头



如果我进行

curl -v --data "hello" example.com

curl发送

POST / HTTP/1.1
Host: example.com
User-Agent: curl/7.77.0
Accept: */*
Content-Length: 5
Content-Type: application/x-www-form-urlencoded
hello

我知道我可以传递-X 'Content-Type: something/else来更改Content-Type标头的值,但有没有一种方法可以在根本不设置该标头的情况下发送数据?

要告诉curl根本不发送头,请使用-H传递不带值的头,如下所示(引号不是绝对必要的(:

curl --data hello -H 'Content-Type:' example.com

这将发送以下请求:

POST / HTTP/1.1
Host: example.com
User-Agent: curl/7.77.0
Accept: */*
Content-Length: 5
hello 

来自-H标志的卷曲手册页:

通过在冒号右侧提供不包含内容的替换来删除内部标头,如:-H "Host:"中所示。如果发送没有值的自定义标头,则其标头必须以分号终止,例如-H "X-Custom-Header;"以发送";X-Custom-Header:";。

相关内容

最新更新