note 94405 modified in function.curl-setopt by danbrown
| From: | danbrown@php.net | Date: | Sun, 09 Jan 2011 16:48:24 +0000 |
| Subject: | note 94405 modified in function.curl-setopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175565@lists.php.net to get a copy of this message | ||
If you change the post array to a string, PHP creates the post data successfully.
As a quick and dirty example of implementing this fix:
<?php
$ch = curl_init;
$url = 'http://www.example.com';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
foreach ($postData as $var) if (strpos($var, '@') === 0) {
$postAsString = true;
}
if ($postAsString === true) {
$str = '';
foreach ($postData as $key => $val) {
$str .= '&' . $key . '=' . $val;
}
$postData = substr_replace($str, '', 0, 1);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec($ch);
?>
--was--
Following from the comment made by Stan van de Burgt, if you change the post array to a string, PHP
creates the post data successfully.
As a quick and dirty example of implementing this fix:
<?php
$ch = curl_init;
$url = 'http://www.example.com';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
foreach ($postData as $var) if (strpos($var, '@') === 0) {
$postAsString = true;
}
if ($postAsString === true) {
$str = '';
foreach ($postData as $key => $val) {
$str .= '&' . $key . '=' . $val;
}
$postData = substr_replace($str, '', 0, 1);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec($ch);
?>
Hopefully this error gets fixed at a lower level in the PHP cURL library itself to stop the need for
this ugly workaround.
http://php.net/manual/en/function.curl-setopt.php