add simple test data to use loaded Guzzle http client
This commit is contained in:
35
src/index.php
Normal file
35
src/index.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require '../vendor/autoload.php';
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use GuzzleHttp\Psr7\Request;
|
||||||
|
|
||||||
|
$client = new Client();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
|
||||||
|
} catch (GuzzleException $e) {
|
||||||
|
echo $e->getMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $response->getStatusCode() . PHP_EOL;
|
||||||
|
echo $response->getHeaderLine('content-type') . PHP_EOL;
|
||||||
|
echo $response->getBody() . PHP_EOL;
|
||||||
|
|
||||||
|
// asynchronous
|
||||||
|
$request = new Request('GET', 'https://httpbin.org');
|
||||||
|
|
||||||
|
$promise = $client
|
||||||
|
->sendAsync($request)
|
||||||
|
->then(function ($response) {
|
||||||
|
echo 'I completed! ' . $response->getBody();
|
||||||
|
});
|
||||||
|
|
||||||
|
echo "before waiting for response" . PHP_EOL;
|
||||||
|
|
||||||
|
$promise->wait();
|
||||||
|
|
||||||
|
echo "after waiting for response" . PHP_EOL;
|
||||||
Reference in New Issue
Block a user