Guzzle usages

Basic

use GuzzleHttp\Client;

$response = $client->request('POST', 'http://httpbin.org/post', [
    'form_params' => [
        'field_name' => 'abc',
        'other_field' => '123',
        'nested_field' => [
            'nested' => 'hello'
        ]
    ]
]);

$response = $client->request('POST', 'http://httpbin.org/post', [
    'json' => [
        'field_name' => 'abc',
        'other_field' => '123',
        'nested_field' => [
            'nested' => 'hello'
        ]
    ]
]);

$res = $this->client->request(
	'GET', 'members/' . $phone . '/prepaidcards', [
	'query' => [
		'phone' => $phone, 
	]
]);

Get raw response

//Return all data
$contents = (string) $response->getBody();

//getContents returns the remaining contents
$contents = $response->getBody()->getContents();

Example:

use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\StreamInterface;

class HttpTool
{
    public $err = '';

    public function __construct(){

    }

    public function get($url, $data)
    {
        $client = new \GuzzleHttp\Client();

        $response = $client->request('GET', $url, $data);
        //logg($response->getStatusCode());
        if($response->getStatusCode() == 200){
            $res = json_decode($response->getBody());
            return $res;
        }else{
            $this->err = (string)$response->getBody();
            return false;
        }
    }

}

Reference: