PHP code example of understeam / yii2-httpclient

1. Go to this page and download the library: Download understeam/yii2-httpclient 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/ */

    

understeam / yii2-httpclient example snippets


...
'components' => [
	'httpclient' => [
		'class' =>'understeam\httpclient\Client',
		'detectMimeType' => true, // automatically transform request to data according to response Content-Type header
		'requestOptions' => [
		    // see guzzle request options documentation
		],
		'requestHeaders' => [
		    // specify global request headers (can be overrided with $options on making request)
		],
	],
],
...

// Result is html text
$text = Yii::$app->httpclient->get('http://httpbin.org/html');

// Result is SimpleXMLElement containing parsed XML
$xml = Yii::$app->httpclient->get('http://httpbin.org/xml');

// Result is parsed JSON array
$json = Yii::$app->httpclient->get('http://httpbin.org/get');


// Result is Guzzle `Response` object
$text = Yii::$app->httpclient->get('http://httpbin.org/xml', [], false);


$text = Yii::$app->httpclient->get('http://httpbin.org/xml', [
    'proxy' => 'tcp://localhost:8125'
]);

// Synchronous GET request
Yii::$app->httpclient->get(
    $url, // URL
    [], // Options
    true // Detect Mime Type?
);

// Synchronous POST (and others) request
Yii::$app->httpclient->post(
    $url, // URL
    $body, // Body
    [], // Options
    true // Detect Mime Type?
);

// Asynchronous GET request
Yii::$app->httpclient->getAsync(
    $url, // URL
    [] // Options
);

// Asynchronous POST (and others) request
Yii::$app->httpclient->postAsync(
    $url, // URL
    $body, // Body
    [] // Options
);


// PromiseInterface
$promise = Yii::$app->httpclient->postAsync('http://httpbin.org/post');
bash
php composer.phar