note 52548 deleted from function.curl-setopt by danbrown

From: Date: Sun, 17 May 2009 17:32:13 +0000
Subject: note 52548 deleted from function.curl-setopt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154996@lists.php.net to get a copy of this message
Note Submitter: ale at desarrolloweburuguay dot com ---- 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.-

« previous php.notes (#154996) next »