curl-and-php
RE: Issue with sending arrays in CURLOPT_POSTFIELDS
Date: Fri, 10 Jul 2009 11:39:08 +0100
Perfect!
Many thanks again Liu and Stephen, and I'll even promise to spell your name
correctly this time Liu J
Yes - when POST fields are Arrays, the usual $key -> $value pairing produces
incorrect results.
I was getting
string 'basket.shipmentList=Array&Continue.x=40&Continue.y=4' (length=52)
using (notice the _ replacement to . to hack around the fact that php
automatically converts POST variables with .s in the name to be _s)
$postParams = '';
foreach ($_POST as $key => $value) {
$key = str_replace('_', '.', $key);
$postParams .= $key . '=' . $value . '&';
}
where you can see that the key is basket.shipmentList, however the value is
incorrectly set to be Array when it should be the contents of the array.
Here's the correct response using Liu's suggestion of using the
$postParams = file_get_contents("php://input");
which gives the correct result of
string
'basket.shipmentList%5B0%5D.shippingMethod=1&Continue.x=40&Continue.y=4'
(length=70)
Fantastic!! Really owe you guys a beer or two to say thanks J
Alex
Skywire | www.skywire.co.uk | alex at skywire dot co dot uk
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-07-10