1. Go to this page and download the library: Download asika/http 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');
/* Start to develop here. Best regards https://php-download.com/ */
asika / http example snippets
php
use Asika\Http\HttpClient;
$http = new HttpClient;
$response = $http->get('http://example.com/?foo=bar');
// This is PSR7 ResponseInterface
(string) $response->getBody();
php
$http = new HttpClient;
// The post data can be query string or array
$response = $http->post('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->put('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->patch('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->delete('http://example.com/?foo=bar', array('post_data' => 'data'));
$response = $http->head('http://example.com/?foo=bar');
$response = $http->trace('http://example.com/?foo=bar');
$response = $http->options('http://example.com/?foo=bar');
// With headers
$response = $http->get('http://example.com/', null, array('X-Foo' => 'Bar'));
// Use request()
$response = $http->request('POST', 'http://example.com/?foo=bar', 'this=is&post=data');
php
use Asika\Http\Transport\CurlTransport;
$options = array(
'certpath' => '/custom/cert.pem'
);
$transport = new CurlTransport($options);
// Set transport when client new
$http = new HttpClient(array(), $transport);
php
$http = new HttpClient;
$dest = '/path/to/local/file.zip';
$response = $http->download('http://example.com/file.zip', $dest);
if ($response->getStatusCode() != 200)
{
// Error
}
php
// new uri object
$uri = new Asika\Http\Uri\Uri;
$uri->setHost('http://localhost');
$uri->setPort('8888');
$uri->setUser('myUser');
$uri->setPass('myPass');
echo $uri->__toString();
php
// set path
$uri->setPath('path/to/file.php');
php
$stream = new Stream('php://memory', 'wb+');
$stream->write('Foo Bar');
$stream->rewind(); // Back to begin
// Now we take something we wrote into memory
$stream->__toString(); // get: Foo Bar
// OR
$stream->rewind();
$stream->getContents(); // get: Foo Bar