我设法让我的请求“高级REST客户端”的工作使用以下设置:如何发布JSON与PHP和curl?
不过,我尝试使用PHP来重建相同的请求,我不知道是什么我做错了。这里是我有什么:
$config['key'] = "xxxxxxxxxxxx";
$config['clientid'] = xxxxxxxxx;
$url = 'http://xxxxxxxxxxxxxxxx.curdbee.com/invoices.json?api_token='.$config['key'];
$data = Array();
$data['invoice']['client_id'] = $config['clientid'];
$data_string = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
echo curl_error($ch);
print_r($result);
$ result和curl_error都不输出任何东西,我不知道为什么。
可能会添加cookie接受json和更多标题,如浏览器。检查整个原始http请求并查看详细信息。 – Robert
var_dump(curl_getinfo($ ch))的结果是什么? – Pattle
@Pattle http://pastebin.com/yKrithcS – James