note 99108 modified in function.curl-setopt by danbrown
| From: | danbrown@php.net | Date: | Fri, 30 Jul 2010 16:39:01 +0000 |
| Subject: | note 99108 modified in function.curl-setopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171255@lists.php.net to get a copy of this message | ||
Be careful when setting the CURLOPT_POSTFIELDS setting using an array. The array used to set the
POST fields must only contain scalar values. Multidimentional arrays or objects lacking a __toString
implementation will cause Curl to error.
If there is a need to send non-scalar values using a POST request, consider serializing them before
transmission.
<?php
$ch = curl_init('http://host.example.com');
// Data to post
$multiDimensional = array(
'name' = 'foo',
'data' = array(1,2,3,4),
'value' = 'bar'
);
// Will error
curl_setopt($ch, CURLOPT_POSTFIELDS, $multiDimensional);
// Data to post
$postData = array(
'name' = 'foo',
'data' = serialize(array(1,2,3,4)),
'value' = 'bar'
);
// Will not error
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
?>
--was--
Be careful when setting the CURLOPT_POSTFIELDS setting using an array. The array used to set the
POST fields must only contain scalar values. Multidimentional arrays or objects lacking a __toString
implementation will cause Curl to error.
If there is a need to send non-scalar values using a POST request, consider serializing them before
transmission.
<?php
$ch = curl_init('http://some.domain.tld');
// Data to post
$multiDimensional = array(
'name' = 'foo',
'data' = array(1,2,3,4),
'value' = 'bar'
);
// Will error
curl_setopt($ch, CURLOPT_POSTFIELDS, $multiDimensional);
// Data to post
$postData = array(
'name' = 'foo',
'data' = serialize(array(1,2,3,4)),
'value' = 'bar'
);
// Will not error
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
http://php.net/manual/en/function.curl-setopt.php