Created
July 18, 2017 18:33
-
-
Save Stormix/92653dfd13932e9c8aa5c4dfa801b1fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$client = new \GuzzleHttp\Client(); | |
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle'); | |
echo $res->getStatusCode(); | |
// 200 | |
echo $res->getHeaderLine('content-type'); | |
// 'application/json; charset=utf8' | |
echo $res->getBody(); | |
// '{"id": 1420053, "name": "guzzle", ...}' | |
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment