Last active
February 27, 2018 09:17
-
-
Save sagikazarmark/9dd52450aa8746dec5a1499df8570600 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
* Trying ::1... | |
* TCP_NODELAY set | |
* Connection failed | |
* connect to ::1 port 8080 failed: Connection refused | |
* Trying 127.0.0.1... | |
* TCP_NODELAY set | |
* Connected to localhost (127.0.0.1) port 8080 (#0) | |
> GET /server.php HTTP/1.1 | |
Host: localhost:8080 | |
User-Agent: GuzzleHttp/6.3.0 curl/7.54.0 PHP/5.6.30 | |
< HTTP/1.1 200 OK | |
< Host: localhost:8080 | |
< Connection: close | |
< X-Powered-By: PHP/5.6.30 | |
< Content-type: text/html; charset=UTF-8 | |
< | |
* Closing connection 0 | |
Status code: 200 | |
Body size: 43 | |
Stream object type: GuzzleHttp\Psr7\Stream | |
{"id": "1234", "name": "bar \"for\" baz " } | |
array(2) { | |
["id"]=> | |
string(4) "1234" | |
["name"]=> | |
string(14) "bar "for" baz " | |
} |
This file contains hidden or 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 | |
echo '{"id": "1234", "name": "bar \"for\" baz " }'; |
This file contains hidden or 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 -S 0.0.0.0:8080 |
This file contains hidden or 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 | |
require_once __DIR__.'/vendor/autoload.php'; | |
$client = new GuzzleHttp\Client([ | |
'handler' => new \GuzzleHttp\Handler\CurlHandler(), | |
//'handler' => new \GuzzleHttp\Handler\StreamHandler(), | |
]); | |
$response = $client->get( | |
'http://localhost:8080/server.php', | |
[ | |
'debug' => true, | |
] | |
); | |
echo 'Status code: '.$response->getStatusCode()."\n"; | |
echo 'Body size: '.$response->getBody()->getSize()."\n"; | |
echo 'Stream object type: '.get_class($response->getBody())."\n"; | |
$body = $response->getBody(); | |
while (!$body->eof()) { | |
echo $body->read(1024); | |
flush(); | |
} | |
echo "\n\n"; | |
var_dump(json_decode((string) $body, true)); |
This file contains hidden or 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 test.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment