GuzzleHttp\Client don't return any response

GuzzleHttp\Client don't return any response

guzzlehttp\psr7\request
guzzle get response body
guzzlehttpclient laravel
guzzle post json
guzzle json response
guzzle pool
guzzle post request laravel
guzzle github

i'm creating an authentication api using passport from the official docs but i'm stuck on sending GuzzelHttp request

i'v done exactly like the docs but when i want to test with postman no result returned it just stay loading without end

this is my code my controller

$user = new User();
        $user->email = $request->email;
        $user->name = $request->name;
        $user->password = bcrypt($request->password);
        $user->save();

        $http = new Client;

        $response = $http->post('http://localhost:8000/oauth/token', [
            'form_params' => [
                'grant_type' => 'password',
                'client_id' => 2,
                'client_secret' => 'x2ESrkADoQEaQ91iMW9kKiIvjKo0LL4RxlUtqtmy',
                'password' => $request->password
            ],
        ]);
        dd($response);

        return response([
            'success'=> true,
            'successMessageKey' => 'userCreatedSuccessfully' ,
            'data'=>json_decode((string) $response->getBody(), true)
        ]);

and my route

Route::post('users/register',[
'uses' => 'Api\AuthController@register'
]);

and when i run my route i got no result like this and stuck in loading


I findout the problem in your code

please check the parameter which you sent to auth/token. username is missing in your request

Request Options — Guzzle Documentation, Request options control various aspects of a request including, headers, query string $client = new GuzzleHttp\Client(['base_uri' => 'http://httpbin.org']);� Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc


You need pass array of form_params as json

e.g

$response = $http->post('http://localhost:8000/oauth/token', [
            'form_params' => json_encode([
                'grant_type' => 'password',
                'client_id' => 2,
                'client_secret' => 'x2ESrkADoQEaQ91iMW9kKiIvjKo0LL4RxlUtqtmy',
                'password' => $request->password
            ]),
 ]);

Request and Response Messages — Guzzle Documentation, Guzzle is an HTTP client that sends HTTP requests to a server and receives Sometimes you don't know what the entire request will be when it is created. i'm creating an authentication api using passport from the official docs but i'm stuck on sending GuzzelHttp request i'v done exactly like the docs but when i want to test with postman no result


Try including password_confirmation in your parameters in Postman. That's what I did in my laravel passport project

Guzzle, PHP HTTP client — Guzzle Documentation, Create a client with a base URI $client = new GuzzleHttp\Client(['base_uri' Request('HEAD', 'http://httpbin.org/head', $headers, $body); // Or, if you don't need� So, finally we have completed the Laravel Guzzle http client for the RESTful APIs handling. This demo will guide you in the HTTP request handling withe any third party APIs. HTTP Client in Laravel, overcomes the use of cURL request. Hope, it will be very helpful for you.


The issue is when using php artisan serve, it uses a PHP server which is single-threaded.

The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked.

You can do this solution:

When making calls to itself the thread blocked waiting for its own reply. The solution is to either seperate the providing application and consuming application into their own instance or to run it on a multi-threaded webserver such as Apache or nginx.

Or if you are looking for a quick fix to test your updates - you can get this done by opening up two command prompts. The first would be running php artisan serve (locally my default port is 8000 and you would be running your site on http://localhost:8000). The second would run php artisan serve --port 8001.

Then you would update your post request to:

    $response = $http->post('http://localhost:8001/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => 2,
            'client_secret' => 'x2ESrkADoQEaQ91iMW9kKiIvjKo0LL4RxlUtqtmy',
            'password' => $request->password
        ],
    ]);

This should help during your testing until you are able to everything on server or a local virtual host.

FAQ — Guzzle Documentation, Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings,� Using GuzzleHttp with Laravel. Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services..


GuzzleHttp\Client don't return any response, cURL is an amazing HTTP client (arguably the best), and Guzzle will continue to use it by default when it is available. It is rare, but some developers don't have� Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc


HTTP redirects — Guzzle documentation, By providing an object oriented interface for HTTP clients, requests, It is rare, but some developers don't have cURL installed on their systems or run into� Different implementations exist for the GuzzleHttp\Cookie\CookieJarInterface: The GuzzleHttp\Cookie\CookieJar class stores cookies as an array. The GuzzleHttp\Cookie\FileCookieJar class persists non-session cookies using a JSON formatted file. The GuzzleHttp\Cookie\SessionCookieJar class persists cookies in the client session.


Does Guzzle require cURL?, I findout the problem in your code. please check the parameter which you sent to auth/token. username is missing in your request. Request Options¶. You can customize requests created and transferred by a client using request options.Request options control various aspects of a request including, headers, query string parameters, timeout settings, the body of a request, and much more.