|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: tjw at tjw dot org
New email:
PHP Version: OS:


 [2015-05-15 21:00 UTC] tjw at tjw dot org
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-23 18:48 UTC]
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
 [2017-01-28 12:57 UTC]
-Package: Documentation problem +Package: cURL related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 07:01:34 2024 UTC