note 52548 added to function.curl-setopt
| From: | aleatdesarrolloweburuguaydotcom at osu1 dot php dot net | Date: | Thu, 05 May 2005 12:00:34 +0000 |
| Subject: | note 52548 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88963@lists.php.net to get a copy of this message | ||
I don't know if in PHP 5+ this problem is solved, but, when I send via POST using
CURLOPT_POSTFIELDS some times it doesnt work an associative array as parameter... and, if I need to
send non-ascii characters (like á,é,ñ,ü,etc..) this problem appears too.
The solution is to encode in a unique string all the post key=>values
Possibly this code doesnt work:
<?php
$post_data = array();
$post_data['var1'] = "Diseño web uruguay";
$post_data['var2'] = "Other string";
$url = "http://www.someurl.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($ch);
?>
But this works:
<?php
$post_data = array();
$post_data['var1'] = "Diseño web uruguay";
$post_data['var2'] = "Other string";
$url = "http://www.someurl.com/";
$o="";
foreach ($post_data as $k=>$v)
{
$o.= "$k=".utf8_encode($v)."&";
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($ch);
?>
Rgds.
Alejandro Moreno.-
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52548
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52548&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52548&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52548&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52548&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52548&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52548&report=yes
Search -- http://master.php.net/manage/user-notes.php