curl-and-php
Re: Issue with sending arrays in CURLOPT_POSTFIELDS
Date: Wed, 8 Jul 2009 15:04:53 -0400
If I understood you correctly, you're trying to pass an associative array
through POST - the easiest way (the only way I know of, actually) to do this
is as follows:
$array = array("value1", "value2", "value3");
curl_setopt($ch, CURLOPT_POSTFIELDS,
"assoc[]=".$array[0]."&assoc[]=."$array[1]);
At the server side, this will produce an element in the $_POST array keyed
as "assoc", with an array containing the values you passed as a value.
Putting the post data as I have (assoc[]) will produce a simple 0, 1, 2
keying pattern in the passed array, however you can enter custom keys very
simply by just doing:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"assoc[customkey]=".$array[0]."&assoc[anothercustomkey]=."$array[1]);
HTH,
-Stephen
On Wed, Jul 8, 2009 at 13:14, Alex Judd <alex_at_skywire.co.uk> wrote:
> Hi everyone
>
>
>
> Thanks for the reply to my earlier Curl Proxy Cookies question – got that
> all working great thanks to Liu Shan Shut!
>
>
>
> I’m having issues sending Arrays in CURLOPT_POSTFIELDS and wondered if
> there was any advice anyone had on this?
>
>
>
> Basically I have an array of radio boxes, that POST to Curl for it to
> proxy, and in my POST -> CURLOPT_POSTFIELDS function, I try and flatten them
> with $key = $value&$key2 = $value2 etc.
>
>
>
> Arrays however come in as
>
>
>
> $key = ‘key’ and
>
> $value = Array
>
>
>
> And this gets rejected (or at least seem to be) rejected by the server at
> the other end which is expecting a ‘item.array[array number].value’ to come
> through.
>
>
>
> Any ideas as to the best way to deal with this – any advice much
> appreciated!!
>
>
>
> Thanks in advance
>
>
>
> Alex
>
>
>
> Skywire | www.skywire.co.uk | alex <alex_at_skywire.co.uk> at skywire dot co
> dot uk
>
> Please don't print this email and help the environment
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-07-08