2015-09-04 71 views
2

我有將cli cURL轉換爲php cURL版本的問題。 我測試過這樣的鏈接從CLI:將cli curl轉換爲php url

curl -H "X-API-KEY: key" -XPOST -v -H "Accept: application/json" http://sentione.com/api/statements/search -H "Content-Type: application/json" -d '{"topicId":id, "from": "2014-01-01 00:00:00.000 CET"}' 

和它的正常工作。

這就是我的代碼。 我沒有迴應。

$headers = array(
     "Content-type: application/json", 
     "X-API-KEY: key", 
     "Accept: application/json" 
); 
$arr = array(
    "topicId" => id, 
    "from" => "2014-01-01 00:00:00.000 CET" 
); 
$url = "http://sentione.com/api/statements/search"; 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_VERBOSE, true); 
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($arr)); 
$response = curl_exec($curl); 

print_r($response); 

當然,我設置了正確的API密鑰和主題ID。 我在做什麼錯?

+0

我覺得$ curl = curl_init($ url);並刪除它的下一行將幫助你 –

+0

@SunilPachlangia你是不對的。這個語法也是正確的。不管怎麼說,還是要謝謝你 :) – r3m4k3

回答

0

我的不好,請參閱我的數組聲明。 我用:代替=>。我不知道爲什麼。 它已解決,無論如何,謝謝! :)