Php 将带有cURL的JSON对象发送到特定url

Php 将带有cURL的JSON对象发送到特定url,php,json,api,curl,Php,Json,Api,Curl,我不太明白如何格式化对Mandrill API的cURL调用 $specific_api = "/messages/send.json"; $url = "https://mandrillapp.com/api/1.0/" . specific_api . "?"; $param_array = array( 'key' => $apikey, 'template_name' => 'mytemplat

我不太明白如何格式化对Mandrill API的cURL调用

$specific_api = "/messages/send.json";
$url = "https://mandrillapp.com/api/1.0/" . specific_api . "?";

$param_array = array(
                    'key' => $apikey,
                    'template_name' => 'mytemplate',
                    'template_content' => array(
                            'name' => 'main',
                            'content' => 'This is HAPPENING RIGHT NOW!'
                        ),
                    'message' => array(
                        'subject' => 'blanketID Service: Pet Found',
                        'from_email' => 'no-reply@blanketid.com',
                        'from_name' => 'blanketID Service',
                        'to' => array(
                            'email' => 'devinmightbe@gmail.com',
                            'name' => 'Devin Columbus'
                        )
                    )
                );

$encoded = json_encode($param_array);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
$data = curl_exec($ch);
curl_close($ch);
$arr = json_decode($data, true);

echo $data;

我甚至不确定我是否正确地设置了这些内容…

我没有信心,但是在阅读了php.net上有关CURLOPT_POSTFIELDS的文档后,我相信您传递的格式是不被接受的

The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix.

我在想,这是没有意义的?部分..是的,您可以在URL中保留“?”。您正在使用POST请求not GET。