Home > database >  Post data with curl with no Content-Type header
Post data with curl with no Content-Type header

Time:03-24

If I do

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

curl sends

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

I know that I can pass -X 'Content-Type: something/else to change the value of the Content-Type header, but is there a way to send data without that header being set at all?

CodePudding user response:

To tell curl to not send a header at all, pass the header with no value using -H, like this (the quotes are not strictly necessary):

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

this will send this request:

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

hello 

From the curl man page for the -H flag:

Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:". If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".

  •  Tags:  
  • curl
  • Related