我正在使用Guzzle来处理外部API。
我的使用方式如下:
$client = new Client;
$request = $client->request('GET', 'https://api.callrail.com/v1/companies.json', [
'headers' => [
'Authorization' => 'Token token="my_api_string"'
]
]);
return dd($request);
这是输出结果
Stream {#255 ▼
-stream: stream resource @280 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
但是当我只使用像这样的curl时
$api_key = 'my_api_string';
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Token token=\"{$api_key}\""));
$json_data = curl_exec($ch);
return dd($json_data);
输出结果符合预期。
{"page":1,"per_page":100,"total_pages":1,"total_records":11,
....
....
我在使用 Guzzle 时出了问题,不知道哪里做错了?