php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69644 additional note for CURLOPT_POSTFIELDS
Submitted: 2015-05-15 21:00 UTC Modified: 2017-01-28 12:57 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: tjw at tjw dot org Assigned:
Status: Open Package: cURL related
PHP Version: Irrelevant OS: ALL
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: tjw at tjw dot org
New email:
PHP Version: OS:

 

 [2015-05-15 21:00 UTC] tjw at tjw dot org
Description:
------------
If curl_setopt() is used to set CURLOPT_POSTFIELDS with an array, it will not work unless CURLOPT_POST has been set to true first.

This works:

  $parameters = array("test" => "testing");
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);

This posts and empty form:

  $parameters = array("test" => "testing");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
  curl_setopt($ch, CURLOPT_POST, TRUE);

However, this works:

  $parameters = "test=testing";
  curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
  curl_setopt($ch, CURLOPT_POST, TRUE);

It would be very helpful if a note was added in the documentation for  CURLOPT_POSTFIELDS that CURLOPT_POST must be set to true before passing an array or it will not be automatically converted to a query string.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-23 18:48 UTC] pasindu@php.net
In PHP 7 CURLOPT_POST dose not have to be set, in CURLOPT_POSTFIELDS a string is treated as a query string and array will be converted

http://lxr.php.net/xref/PHP_TRUNK/ext/curl/interface.c#2501
 [2017-01-28 12:57 UTC] cmb@php.net
-Package: Documentation problem +Package: cURL related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 12:01:26 2019 UTC