Currently using Laravel 5.5 and Guzzle that comes together with the laravel installer.
I am trying to make GET request (error occur with other HTTP requests as well) but don't seem work.
This code does not work:
public function callback(Request $request)
{
$code = $request->code;
$client = new Client(['exceptions' => false]);
try {
$response = $client->request('GET', 'http://localhost/api/tests');
// $response = $http->request('POST', Config::get('app.url') . '/oauth/token', [
// 'form_params' => [
// 'grant_type' => 'authorization_code',
// 'client_id' => Config::get('oauth_client.client_id'),
// 'client_secret' => Config::get('oauth_client.client_secret'),
// 'redirect_uri' => Config::get('oauth_client.redirect_uri'),
// 'code' => $code,
// ],
// ]);
// return json_decode((string) $response->getBody(), true);
} catch (\Exception $e) {
dd($e);
}
dd($response->getBody());
return;
}
But this code below is work very well
public function callback(Request $request)
{
$code = $request->code;
$client = new Client(['exceptions' => false]);
try {
$response = $client->request('GET', 'https://www.google.co.id');
// $response = $http->request('POST', Config::get('app.url') . '/oauth/token', [
// 'form_params' => [
// 'grant_type' => 'authorization_code',
// 'client_id' => Config::get('oauth_client.client_id'),
// 'client_secret' => Config::get('oauth_client.client_secret'),
// 'redirect_uri' => Config::get('oauth_client.redirect_uri'),
// 'code' => $code,
// ],
// ]);
// return json_decode((string) $response->getBody(), true);
} catch (\Exception $e) {
dd($e);
}
dd($response->getBody());
return;
}
I'm not understand why my Guzzle able to request to google.com but unable to connect to my own localhost server (to all ports).
Any help will greatly appreciate.
Thanks,
Using Apache2 and Virtual Host for my development server solved the problem, this approach more realistic than making any changes on my Guzzle parameters.
So my conclusion is Better to use real web server (Nginx, Apache) rather than artisan serve.