我开始将GuzzleHttp与Laravel一起使用,我已经创建了我的第一个请求,但我没有得到与使用 CURL 在 bash 中相同的结果:
这是我的 Guzzle 请求:
public static function all(){
$client = new Client([
'base_uri' => 'https://api.my-endpoint-domain.io'
]);
try{
$response = $client->request('GET', '/stats', [
'headers' => [
'Authorization' => 'Bearer a2bc3699e43bdf45804701166f658a3c14ba5c',
'Content-Type' => 'application/json',
'Cache-Control' => 'no-cache'
]
]);
print_r($response->getBody());
} catch(GuzzleException $e){
return response()->json([
'error' => $e->getMessage()
], 500);
}
}
这是我的结果:
GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #12
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
烙印99