簡體   English   中英

我正在嘗試 cURL 這個簡單的 URL 在 PHP 中,我不知道我做錯了什么

[英]I'm trying to cURL this simple URL in PHP and I can't figure out what I'm doing wrong

我正在嘗試 cURL 這個 URL 我不知道我做錯了什么。 我真的很感激一些幫助!

這是我的代碼(取出我的 API 令牌)

$url ='https://app.files.com/api/rest/v1/users/0.json'; 

$header = array("Accept: application/json, X-FilesAPI-Key: FakeKeyGoesHere");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 
1.0.3705; .NET CLR 1.1.4322)');
$retValue = curl_exec($ch);

print_r($retValue);

有兩個問題:

  1. $header的格式不正確。 它必須是一個數組,每個元素一個元素 header,但您將它們全部放在一個字符串中。

嘗試

$header = array("Accept: application/json", "X-FilesAPI-Key: FakeKeyGoesHere");
  1. 不要使用curl_setopt($ch, CURLOPT_ENCODING, "gzip"); ,如果數據以另一種編碼形式出現 - 結果將是一團糟。 使用curl_setopt($ch, CURLOPT_ENCODING, ""); 用於輸入編碼自動檢測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM