简体   繁体   English

如何编写用于以下CURL命令的php代码?

[英]How to write php code for following CURL command?

How to write php code for following CURL command? 如何编写用于以下CURL命令的php代码?

curl -H "Authorization: Bearer oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L" https://api.url.com/v1/market/total-items.json curl -H“授权:bearer oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L” https://api.url.com/v1/market/total-items.json

I think you need something like this: 我想你需要这样的东西:

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

You can generate PHP code for your cURL command here from a github branch . 您可以从github 分支为此生成cURL命令的PHP代码。 Here is the one generated for your request: 这是为您的请求生成的:

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

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

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