php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16305 curl post doesn't behave as per the manual
Submitted: 2002-03-27 03:49 UTC Modified: 2002-04-04 07:50 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: reywob at f2s dot com Assigned:
Status: Closed Package: cURL related
PHP Version: 4.1.2 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: reywob at f2s dot com
New email:
PHP Version: OS:

 

 [2002-03-27 03:49 UTC] reywob at f2s dot com
The curl extension is not behaving as described in the manual.

If you set CURLOPT_POST to 1, and then pass an array to CURLOPT_POSTFIELDS, it sets Content-type to multipart/form-data instead of application/x-www-form-urlencoded.  This is wrong: the multipart header should only be used when CURLOPT_PUT is set.  To quote the PHP manual:

{{{CURLOPT_POST: Set this option to a non-zero value if you want PHP to do a regular HTTP POST. This POST is a normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.}}}


Here is what the author of curl (Daniel Stenberg) says - full message at <http://curl.haxx.se/mail/curlphp-2001-11/0003.html>:

{{{I took a tour into the inner workings of the php curl wrapper code and I've now returned to tell about my findings! ;-)

When you pass an array to CURLOPT_POSTFIELDS, it is passed as a multipart/form-data post exactly as you describe. The problem with this is that it uses the libcurl function curl_formparse() to accomplish this, and that is a lame function(*).

It does not support newlines in the contents like you tried here.

The wrapper should instead use the new (and much better) curl_formadd() function for this purpose. It does not have this newline problem.

(*) = yet it was the only available one for a very long time.}}}

I think there is enough evidence here to change the behaviour of the extension - I think it can be done without breaking backwards compatibility.  The extension was never meant to behave like this, as the manual testifies.

Regards,
Peter Bowyer.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-04 07:34 UTC] sniper@php.net
PHP 4.2.0-dev does not use curl_formparse..please try
the RC2 from http://www.php.net/~derick/

 [2002-04-04 07:44 UTC] reywob at f2s dot com
Unfortunately, like 90% of people using PHP I am reliant on my host for compiling and installing PHP, so I can't test it :-(
 [2002-04-04 07:50 UTC] sniper@php.net
Reopen if this doesn't work in PHP 4.2.0.
(works fine here)

 [2002-04-04 17:41 UTC] daniel at haxx dot se
I am Daniel Stenberg, quoted below. That quote is rather old and does not apply to recent PHP.

What *is* the essence of this report, AFAICT, is somewhat confused (and the PUT part is entirely incorrect) but I'll try to sum up things:

The bug report should've said:

If you set CURLOPT_POST to 1, and then pass an array to
CURLOPT_POSTFIELDS, it sets Content-type to multipart/form-data instead of application/x-www-form-urlencoded.

I believe this is still true in the most recent versions of ext/curl/curl.c, but I may be mistaking.

Again, if you pass an array it makes a multipart formpost, if you pass a string it makes a regular http post.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC