duanpin2009 2014-07-17 14:46
浏览 55
已采纳

将CURL命令行转换为PHP [重复]

This question already has an answer here:

How can I convert to PHP Curl?

curl -X GET \<br>
-H "X-Parse-Application-Id: APPIDKEY" \<br>
-H "X-Parse-REST-API-Key: RESTAPIKEY" \<br>
-G \<br>
data-urlencode 'where={"playerName":"Sean Plott"' \<br>
https://api.parse.com/1/classes/ClassName<br>

I have tried:

$ch = curl_init();<br>
curl_setopt($ch, CURLOPT_URL, "https://api.parse.com/1/classes/ClassName");<br>
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Parse-Application-Id: APPIDKEY","X-Parse-    REST-API-Key: RESTAPIKEY"));<br>
curl_setopt($ch, CURLOPT_POST, true);<br>
curl_setopt($ch, CURLOPT_POSTFIELDS, 'where={"playerName":"Sean Plott"}');<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br>
$player = curl_exec($ch);<br>
curl_close($ch);<br>
var_dump($player);

but the result is:bool(false)!

</div>
  • 写回答

1条回答 默认 最新

  • donglun4521 2014-07-17 15:14
    关注

    Also remove the CURLOPT_CUSTOMREQUEST and CURLOPT_POST, CURLOPT_POSTFIELDS and append the data passed in postfields to CURLOPT_URL. TRY THIS CODE.

    $data = 'where={"playerName":"Sean Plott"}';
    $url = 'https://api.parse.com/1/classes/ClassName';
    $requestUrl = $url . '?' . url_encode($data);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $requestUrl);
    curl_setopt($ch, CURLOPT_HTTPHEADER, 
      array(
        "X-Parse-Application-Id: APPIDKEY",
        "X-Parse-REST-API-Key: RESTAPIKEY"
      )
    );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $player = curl_exec($ch);
    curl_close($ch);
    var_dump($player);
    

    HTH,

    VR

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?