我开始将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 ( ))
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
您需要使用它getContents()
来检索所有数据,因此您可以使用以下方法替换打印语句:
print_r($response->getBody()->getContents());
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报
0/150
提交
取消