Guzzle无法向本地主机发出GET请求(端口:80、8000、8080等)

编程入门 行业动态 更新时间:2024-10-26 02:25:02
本文介绍了Guzzle无法向本地主机发出GET请求(端口:80、8000、8080等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当前使用的是Laravel安装程序随附的Laravel 5.5和Guzzle.

Currently using Laravel 5.5 and Guzzle that comes together with the laravel installer.

我正在尝试发出GET请求(其他HTTP请求也会发生错误),但似乎无法正常工作.

I am trying to make GET request (error occur with other HTTP requests as well) but don't seem work.

此代码不起作用:

public function callback(Request $request) { $code = $request->code; $client = new Client(['exceptions' => false]); try { $response = $client->request('GET', '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', '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; }

我不明白为什么我的Guzzle能够请求google却无法连接到我自己的本地主机服务器(连接到所有端口).

I'm not understand why my Guzzle able to request to google but unable to connect to my own localhost server (to all ports).

任何帮助将不胜感激.

谢谢

推荐答案

将Apache2和虚拟主机用于我的开发服务器可以解决此问题,这种方法比对我的Guzzle参数进行任何更改都更现实.

Using Apache2 and Virtual Host for my development server solved the problem, this approach more realistic than making any changes on my Guzzle parameters.

因此,我的结论是,最好使用真正的Web服务器(Nginx,Apache),而不要使用工匠服务.

So my conclusion is Better to use real web server (Nginx, Apache) rather than artisan serve.

更多推荐

Guzzle无法向本地主机发出GET请求(端口:80、8000、8080等)

本文发布于:2023-10-07 12:44:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469417.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   主机   Guzzle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!