如何編寫以下CURL命令的php代碼?如何編寫以下CURL命令的php代碼?
捲曲-H 「授權:承載oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L」 https://api.url.com/v1/market/total-items.json
如何編寫以下CURL命令的php代碼?如何編寫以下CURL命令的php代碼?
捲曲-H 「授權:承載oVi4yPxk1bJ64Y2qOsLJ2D2ZlC3FpK4L」 https://api.url.com/v1/market/total-items.json
我想你需要的東西是這樣的:
<?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);
可以從github上branch這裏生成的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);
什麼都沒顯示:( http://horrorlab.com/envato/newv.php – pskkar
您的嘗試在哪裏? – Thamilan
我將從web服務器運行php文件,它將以https://api.url.com/v1/market/total-items.json的json格式返回數據。 – pskkar