PHP - 无法获得正确的关联数组结构

I try to send a request to an API (mailchimp) using cURL. It works with GET, however, I have problems converting the GET-URl into a proper associative PHP array to send via POST. EDIT Because as MarcB commented, GET requests have some negative sides, like a lenght limit, etc.

Please note that I replaced the values of the variables with asteriks (*).
This is the working GET-parameter:

https://us3.api.mailchimp.com/2.0/ecomm/order-add.json?apikey=***
&order[id]=***
&order[campaign_id]=***
&order[email_id]=***
&order[total]=***
&order[store_id]=***
&order[items][0][product_id]=***
&order[items][0][category_id]=***
&order[items][0][category_name]=***
&order[items][1][product_id]=***
&order[items][1][category_id]=***
&order[items][1][category_name]=***
...


This is the PHP array for the POST request:

Array
(
    [apikey] => ***
    [order] => Array
        (
            [id] => ***
            [campaign_id] => ***
            [email_id] => ***
            [total] => ***
            [order_date] => ***
            [shipping] => ***
            [tax] => ***
            [store_id] => ***
            [store_name] => ***
            [items] => Array
                (
                    [0] => Array
                        (
                            [product_id] => ***
                            [category_id] => ***
                            [category_name] => ***
                        )

                    [1] => Array
                        (
                            [product_id] => ***
                            [category_id] => ***
                            [category_name] => ***
                        )

                    ...

                )

        )

)


Response is:

Validation error: {\"order\":\"Please enter a struct\\\/associative array\"}


Any idea, what I am missing here? Isn't the structure here the same?

--
UPDATE:
This is the curl code:

function httpPost($url,$params)
{
  $postData = '';
   //create name value pairs seperated by &
   foreach($params as $k => $v) 
   { 
      $postData .= $k . '='.$v.'&'; 
   }
   rtrim($postData, '&');

    $ch = curl_init();  

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_POST, count($postData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);    

    $output=curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);
    return array($output, $httpCode);

}

print_r( httpPost( $mc_api_url, $curl_data ) );

OK for starters, you should not be manually building a query string. You should either simply pass your associative array to CURLOPT_POSTFIELDS or build the query string using something like http_build_query() (http://www.php.net/manual/en/function.http-build-query.php).

Second, you should use a value of true for your CURLOPT_POST field.

Of course this is all assuming that API is expecting an application/x-www-form-urlencoded POST request. My guess is that this may not be the case, as your response seem like it is in JSON.

A brief glance of the MailChimp API documentation at http://apidocs.mailchimp.com/api/2.0/

Notes this:

Request data is passed to the API by POSTing JSON objects to the API endpoints with the appropriate parameters.

If you are actually using this API version, then my guess is you need to do be forming JSON objects in the expected format nd using application/json as ContentType header.

If it helps, I have a very lightweight cURL-based REST client that you are welcome to use to more easily interact with RESTful services. Check it out here: https://github.com/mikecbrant/php-rest-client

I had the same error, and got it to work by adding a few extra conditions to my curl call. Try adding these and see if it works:

$data = json_encode($data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);