cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

RE: Posting multiple values for a single key

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 3 Jul 2008 22:36:52 +0200 (CEST)

On Thu, 3 Jul 2008, David Yamanoha wrote:

> I did. PhP provides a mechanism through posting, such that if you provide
> multiple inputs with the same name, followed by array notation, i.e.
> category[], category[], category[], you will receive the POST in an array,
> where category[0] ... category[2] contains the the values you input. As far
> as I know, doing this through cURL is not an option.

I think you're wrong, at least for "normal" posts. Although I don't know much
about PHP and the PHP/CURL binding does have more restrictions than libcurl
itself does.

> If you have an associative array, you can only associate one key value per
> key.

Yes, and that's one of the primary reasons I dislike the way PHP/CURL supports
multipart formposts. The second reason on my list would be that you cannot
specify in which order they go in the data.

> I'm not sure why there aren't any other documented cases of people having
> problems with this... unless there's a simple solution to the problem.
>
> So to clarify, the post data literally is looked something like this:
>
> username : Me
> password : lateda
> categoryChoice[] : 232234
> categoryChoice[] : 12
> cateogryChoice[] : random string
> acceptTOS: true

But this is posted as a normal POST, isn't it? You don't need nor want the
associative array then but you specify your data like this:

"username=me&password=lateda&categoryChoice[]=232234&categoryChoice[]=12&cateogryChoice[]=random%20string&acceptTOS=true"

Possibly the [] need to be %5B%5d instead. LiveHTTPHeaders would show...

-- 
  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-07-03