无法执行curl请求PHP?(Unable to execute curl request PHP?)
我正在处理curl,并尝试从url获取结果,当我通过命令提示符点击url然后它可以工作,但是当我尝试通过curl命中它然后它没有返回任何响应。
这是我尝试过的URL和curl请求:
$request = 'https://api.twilio.com/2010-04-01/Accounts/<AccountSid>/Calls/<SID>/Recordings.json -u <AccountSid>:<AccountToken>';
当我尝试通过终端点击上面的URL然后它工作:
$ curl -G https://api.twilio.com/2010-04-01/Accounts/<AccountSid>/Calls/<SID>/Recordings.json -u <AccountSid>:<AccountToken>
它以json格式返回响应,但我想通过curl访问它,所以我尝试了以下方式:
$session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); echo "<pre>"; print_r($response); echo "</pre>";
但它什么也没有回报。
I am working on curl, and trying to get results from a url, when I hit the url through command prompt then it works, but when I try to hit it through curl then it returns nothing in response.
Here is the URL and the curl request I tried:
$request = 'https://api.twilio.com/2010-04-01/Accounts/<AccountSid>/Calls/<SID>/Recordings.json -u <AccountSid>:<AccountToken>';
When I try to hit the above URL via terminal then it works:
$ curl -G https://api.twilio.com/2010-04-01/Accounts/<AccountSid>/Calls/<SID>/Recordings.json -u <AccountSid>:<AccountToken>
it returns response in json format, but I want to access it throught curl, so I tried the following way:
$session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); echo "<pre>"; print_r($response); echo "</pre>";
but it returns nothing.
原文:https://stackoverflow.com/questions/44345677