1

如何为以下 CURL 命令编写 php 代码?

curl -H “授权:承载 oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L” https://api.url.com/v1/market/total-items.json

4

2 回答 2

2

我认为你需要这样的东西:

<?php 

        $url = "https://api.url.com/v1/market/total-items.json"; 
        $page = "/v1/market/total-items.json";
        $headers = array( 
            "POST ".$page." HTTP/1.0", 
            "Authorization: Bearer oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L" 
        ); 

        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

        $data = curl_exec($ch); 
于 2016-04-26T05:42:02.993 回答
1

您可以在此处从 github分支为您的 cURL 命令生成 PHP 代码。这是为您的请求生成的:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.url.com/v1/market/total-items.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Bearer oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
于 2016-04-26T05:47:49.277 回答