0

我设法让我的请求使用以下设置在“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 都没有输出任何东西,我不知道为什么。

4

2 回答 2

0

我只需要添加这两行:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

于 2013-07-05T15:50:10.210 回答
-1

尝试这个

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $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))                                                                       
);
于 2013-07-05T14:03:16.133 回答