简体   繁体   English

将CLI curl转换为PHP URL

[英]Converting cli curl to php url

I have problem with converting cli cURL to php cURL version. 我将cli cURL转换为php cURL版本时遇到问题。 I've tested such link from cli: 我已经从cli测试了这样的链接:

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"}' 

and it's working properly. 并且工作正常。

And that's my code. 那就是我的代码。 I got no response. 我没有回应。

 $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);

Of course I set correct api key and topic id. 当然,我设置了正确的API密钥和主题ID。 What am I doing wrong? 我究竟做错了什么?

My bad, see at my array declaration. 不好,请参阅我的数组声明。 I used : instead of =>. 我用了:而不是=>。 I don't know why. 我不知道为什么 It's solved, thanks anyway! 解决了,还是谢谢! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM