PHP code example of evaisse / simple-http-bundle
1. Go to this page and download the library: Download evaisse/simple-http-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
evaisse / simple-http-bundle example snippets
$http = $this ->container->get('http' );
$http = $this ->get('http' );
try {
$http->GET('http://httpbin.org/ip' );
} catch (\Symfony\Component\HttpKernel\Exception \HttpException $e) {
}
try {
$data = $http->POST('http://httpbin.org/post' , $myArgs);
} catch (\Symfony\Component\HttpKernel\Exception \HttpException $e) {
}
$data = $http->GET('http://httpbin.org/status/{code}' , array (
"code" => 200
));
$data = $http->GET('http://httpbin.org/status/{code}' , array (
"code" => 200 ,
"foo" => "bar"
));
$transac = $http->prepare('GET' , 'http://httpbin.org/ip' );
$transac->execute();
$a = $http->prepare('GET' , 'http://httpbin.org/ip' );
$b = $http->prepare('PUT' , 'http://httpbin.org/put' );
$c = $http->prepare('POST' , 'http://httpbin.org/post' );
$http->execute([
$a,
$b,
$c
]);
$a->hasError() || $a->getResult();
$b->hasError() || $b->getResult();
$c->hasError() || $c->getResult();
print $http->prepare('POST' , 'http://httpbin.org/ip' , $_SERVER)
->json()
->execute()
->getResult()['ip' ];
$http->prepare('PUT' , 'http://httpbin.org/put' )
->addFile('f1' , './myfile.txt' )
->addFile('f2' , './myfile.txt' )
->execute();
$http->prepare('POST' , 'http://httpbin.org/post' , [
'infos' => 'foo' ,
'bar' => 'so so' ,
])
->addFile('f1' , './myfile.txt' )
->addFile('f2' , './myfile.txt' )
->execute();
$a = $http->prepare('GET' , 'http://httpbin.org/ip' );
$b = $http->prepare('PUT' , 'http://httpbin.org/put' );
$c = $http->prepare('POST' , 'http://httpbin.org/post' );
$cookies = $http->getDefaultCookieJar();
$http->execute([
$a,
$b,
$c
], $cookies);
dump($cookies);
$stmt = $http->prepare('PUT' , 'http://httpbin.org/put' )
$stmt->onSuccess(function ($data) {
})->onError(function (\Symfony\Component\HttpKernel\Exception\HttpException $e) {
})->onFinish(function () {
});
$http->execute([
$stmt
]);