1. 程式人生 > >Laravel 5.6 安裝 guzzlehttp

Laravel 5.6 安裝 guzzlehttp

環境:Laravel 5.6

安裝  composer require guzzlehttp/guzzle


在vendor資料夾下,vendor\guzzlehttp\guzzle引入useGuzzleHttp\Client;官方例子
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
    'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();
// "200"
echo $res->
getHeader('content-type'); // 'application/json; charset=utf8' echo $res->getBody(); // {"type":"User"...' // Send an asynchronous request. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org'); $promise = $client->sendAsync($request)->then(function ($response) { echo 'I completed! '
. $response->getBody(); }); $promise->wait();