note 117009 added to curl.examples-basic

From: Date: Wed, 01 Apr 2015 09:45:43 +0000
Subject: note 117009 added to curl.examples-basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-202120@lists.php.net to get a copy of this message
It is important to notice that when using curl to post form data and you use an array for CURLOPT_POSTFIELDS option, the post will be in multipart format <?php $params=['name'=>'John', 'surname'=>'Doe', 'age'=>36) $defaults = array( CURLOPT_URL => 'http://myremoteservice/', CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params, ); $ch = curl_init(); curl_setopt_array($ch, ($options + $defaults)); ?> This produce the following post header: --------------------------fd1c4191862e3566 Content-Disposition: form-data; name="name" Jhon --------------------------fd1c4191862e3566 Content-Disposition: form-data; name="surnname" Doe --------------------------fd1c4191862e3566 Content-Disposition: form-data; name="age" 36 --------------------------fd1c4191862e3566-- Setting CURLOPT_POSTFIELDS as follow produce a standard post header CURLOPT_POSTFIELDS => http_build_query($params), Which is: name=John&surname=Doe&age=36 This caused me 2 days of debug while interacting with a java service which was sensible to this difference, while the equivalent one in php got both format without problem. ---- Server IP: 72.52.91.14 Probable Submitter: 151.13.19.248 ---- Manual Page -- http://php.net/manual/en/curl.examples-basic.php Edit -- https://master.php.net/note/edit/117009 Del: integrated -- https://master.php.net/note/delete/117009/integrated Del: useless -- https://master.php.net/note/delete/117009/useless Del: bad code -- https://master.php.net/note/delete/117009/bad+code Del: spam -- https://master.php.net/note/delete/117009/spam Del: non-english -- https://master.php.net/note/delete/117009/non-english Del: in docs -- https://master.php.net/note/delete/117009/in+docs Del: other reasons-- https://master.php.net/note/delete/117009 Reject -- https://master.php.net/note/reject/117009 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202120) next »