【发布时间】:2011-06-28 18:21:43
【问题描述】:
我发现如果我尝试 PHP POST curl,postvars 可以正常发送。一旦我添加了内容类型的httpheader:application/json,postvars 就不会再出现了。我已经尝试将 postvars 作为 JSON 字符串和查询字符串。
显示一些代码:
$ch = curl_init();
$post = json_encode(array('p1' => 'blahblahblah', 'p2' => json_encode(array(4,5,6))));
$arr = array();
array_push($arr, 'Content-Type: application/json; charset=utf-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'https://example.com/file.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);
【问题讨论】:
-
我在 $post 上运行了 json_encode。这还不够吗,或者请求正文是什么/其他地方?
-
近乎...我不认为是这样...
标签: php json curl http-headers