Guzzle POST request laravel code example

Example 1: guzzle post request with data

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

Example 2: use guzzle http client laravel

public function putGuzzleRequest()

{

    $client = new \GuzzleHttp\Client();

    $url = "http://myexample.com/api/posts/1";

    $myBody['name'] = "Demo";

    $request = $client->put($url,  ['body'=>$myBody]);

    $response = $request->send();



    dd($response);

}

Example 3: laravel http client

composer require guzzlehttp/guzzle

Example 4: laravel http client

use Illuminate\Support\Facades\Http;

$response = Http::get('http://test.com');

Example 5: post request data not getting from guzzle laravel

use Illuminate\Support\Facades\Http;

Http::fake();

$response = Http::post(...);