php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42821 postfields when set through curl_setopt_array not set properly
Submitted: 2007-10-01 20:52 UTC Modified: 2007-10-13 13:14 UTC
From: admin at anyame dot co dot uk Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.4 OS: fedora4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at anyame dot co dot uk
New email:
PHP Version: OS:

 

 [2007-10-01 20:52 UTC] admin at anyame dot co dot uk
Description:
------------
When setting a number of curl options through curl_setopt_array and using post, the postfields options are not being set properly and are reported as errored in the response. When the curl_setopt options are set seperately then the response is valid.

This is for postfields only. Setting the curl options through curl_setopt_array and seperately for GET work ok

php 5.2.4'./configure' \
'--with-apxs=/usr/local/apache/bin/apxs' \
'--prefix=/usr/local' \
'--with-mysql=/usr' \
'--with-mysqli' \
'--with-openssl' \
'--enable-discard-path' \
'--with-pear' \
'--enable-sockets' \
'--enable-pcntl' \
'--with-xml' \
'--enable-bcmath' \
'--enable-calendar' \
'--with-curl' \
'--with-curlwrappers' \
'--with-dom' \
'--with-dom-xslt' \
'--with-dom-exslt' \
'--enable-ftp' \
'--with-gd' \
'--with-jpeg-dir=/usr/local' \
'--with-png-dir=/usr' \
'--with-xpm-dir=/usr/X11R6' \
'--with-mcrypt' \
'--enable-track-vars' \
'--enable-mbstring' \
'--with-zlib' \
'--with-bz2' \
'--enable-inline-optimization' \
'--disable-debug' \
'--without-pic' \

ini using recommended with short-tags on.


Reproduce code:
---------------
Works - using yahoo webservice example. Freely available at http://developer.yahoo.com/search/siteexplorer/V1/inlinkData.html
------
<?php
error_reporting(E_ALL);
// The POST URL and parameters
$request= 'http://search.yahooapis.com/SiteExplorerService/V1/inlinkData';
$appid = 'YahooDemo';
$query = 'http://search.yahoo.com';
$postargs = 'appid='.$appid.'&query='.urlencode($query).'&results=2';
$ch = curl_init($request);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Output the XML
echo htmlspecialchars($xml, ENT_QUOTES);

ERRORS in xml
-------------
<?php
error_reporting(E_ALL);
// The POST URL and parameters
$request=  'http://search.yahooapis.com/SiteExplorerService/V1/inlinkData';
$appid = 'YahooDemo';
$query = 'http://search.yahoo.com';
$postargs = 'appid='.$appid.'&query='.urlencode($query).'&results=2';
$ch = curl_init($request);
$options = array(CURLOPT_POST => true,
		 CURLOPT_POSTFIELDS, $postargs,
		 CURLOPT_FOLLOWLOCATION => true,
		 CURLOPT_HEADER => false,
		 CURLOPT_RETURNTRANSFER => true);
curl_setopt_array ($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
echo htmlspecialchars($xml, ENT_QUOTES);


Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?> <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:srch" xsi:schemaLocation="urn:yahoo:srch http://api.search.yahoo.com/SiteExplorerService/V1/InlinkDataResponse.xsd" totalResultsAvailable="116746" firstResultPosition="1" totalResultsReturned="2"> <Result><Title>Yahoo!</Title><Url>http://www.schakolad.com/</Url><ClickUrl>http://www.schakolad.com/</ClickUrl></Result> <Result><Title>Common Dreams | News &amp;amp; Views</Title><Url>http://www.commondreams.org/</Url><ClickUrl>http://www.commondreams.org/</ClickUrl></Result> </ResultSet> <!-- se1.search.re4.yahoo.com uncompressed/chunked Mon Oct 1 13:39:48 PDT 2007 --> <!-- ws05.search.re2.yahoo.com uncompressed/chunked Mon Oct 1 13:39:48 PDT 2007 -->

Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?> <Error xmlns="urn:yahoo:api">  The following errors were detected: <Message>invalid value: appid</Message>  <Message>invalid value: query</Message> </Error> <!-- ws06.search.re2.yahoo.com uncompressed/chunked Mon Oct 1 13:51:02 PDT 2007 -->

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-13 13:14 UTC] mj@php.net
Your code is wrong:

$options = array(CURLOPT_POST => true,
		 CURLOPT_POSTFIELDS, $postargs,
		 CURLOPT_FOLLOWLOCATION => true,
		 CURLOPT_HEADER => false,
		 CURLOPT_RETURNTRANSFER => true);

should be

$options = array(CURLOPT_POST => true,
		 CURLOPT_POSTFIELDS => $postargs,
		 CURLOPT_FOLLOWLOCATION => true,
		 CURLOPT_HEADER => false,
		 CURLOPT_RETURNTRANSFER => true);

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC