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
 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 04:01:26 2024 UTC