php [guzzle php] guzzle php #php

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [guzzle php] guzzle php #php相关的知识,希望对你有一定的参考价值。

<?php
//http://docs.guzzlephp.org/en/stable/
$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();

以上是关于php [guzzle php] guzzle php #php的主要内容,如果未能解决你的问题,请参考以下文章