环境:Laravel 5.6

安装  composer require guzzlehttp/guzzle

Laravel 5.6 安装 guzzlehttp

在vendor文件夹下,vendor\guzzlehttp\guzzle
引入
use GuzzleHttp\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();

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-06-14
  • 2022-01-26
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
相关资源
相似解决方案