我设法让我的请求使用以下设置在“Advanced Rest Client”中工作:
但是,我尝试使用 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 都没有输出任何东西,我不知道为什么。