任何人都可以帮我解决我的问题,我正试图在Laravel 5中使用Guzzle并尝试从Rest API中检索数据。当我dd()时,我总是得到这个。
Stream {#287 ▼
-stream: :stream {@11 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
这是我的控制器,不确定我是否正确地与guzzle集成。
<?php namespace App\Http\Controllers;
class SampleController extends \SleepingOwl\Admin\Controllers\AdminController {
public function getIndex() {
$client = new \GuzzleHttp\Client();
$response = $client->get('http://httpbin.org/get');
$body = $response->getBody();
dd($body);
//return \View::make('samplerest')->with('tests',$body);
}
}
答案 0 :(得分:1)
你也可以像这样使用$response->json();
:
$client = new \GuzzleHttp\Client();
$response = $client->get('http://httpbin.org/get');
$json = $response->json();
请注意,如果响应格式不正确,它会抛出异常。