cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: "content-type:application/x-www-form-urlencoded" is wrongly added implicitly when data to be posted is 0

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 19 Mar 2012 16:50:45 +0100 (CET)

On Mon, 19 Mar 2012, Xiang Guan wrote:

>  As "http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTHTTPPOST"
> said:
>      "A parameter set to 1 tells the library to do a regular HTTP
> post. This will also make the library use a "Content-Type:
> application/x-www-form-urlencoded" header. (This is by far the most
> commonly used POST method)"

You're mixing matters. The URL you mention is about doing multipart/formdata
posts but the text you quote is for the CURLOPT_POST option.

>     When I set data to be posted to zero(CURLOPT_POSTFIELDSIZE = 0 or
> CURLOPT_POSTFIELDSIZE_LARGE = 0), I think curl should not add "Content-Type:
> application/x-www-form-urlencoded" any more, because there are not any data
> , it does not make any sense to set this header. In a real world some
> servers get this header without any data will have a wrong behavior to send
> back wrong data to browser client.

Can you please be more specific about "some servers" ? curl has *always*
behaved like this and after having supported HTTP POST for 12 years or so I
would imagine your case is rather uncommon. HTTP spec wise, curl is also
correct and your server wrong.

Besides that, you can easily disable the header if you want to for your
request.

-- 
  / daniel.haxx.se

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-19