我需要将一个复杂的数组发送到一个API,它只能将一个数组作为正文。它的工作原理很简单。但是当我发送一个多维数组时,例如:
array (size=44)
'id' => int 2707
'model' => string 'test55' (length=6)
'admin_title' => string 'test55' (length=6)
'status' => boolean true
'special' => boolean false
'created_at' =>
array (size=3)
'date' => string '2016-02-29 09:34:12' (length=19)
'timezone_type' => int 3
'timezone' => string 'Europe/Paris' (length=12)
'updated_at' =>
array (size=3)
'date' => string '2016-02-29 13:42:51' (length=19)
'timezone_type' => int 3
'timezone' => string 'Europe/Paris' (length=12)
...
我收到错误:
Array to string conversion.
这是我的卷曲设置:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'url');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/x-www-form-urlencoded, Content-type: application/x-www-form-urlencoded')); // Assuming you're requesting JSON
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $decoded);
$response = curl_exec($ch);
$result = json_decode($response, true);
var_dump($result);
curl_close($ch);
die;
如果我使用hhtp_build_query,它会创建一个字符串作为数据,并且应用程序不接受它...我该怎么办?