【问题标题】:GuzzleHttp Laravel - Could not resolve host: myapplication.devGuzzleHttp Laravel - 无法解析主机:myapplication.dev
【发布时间】:2019-03-28 17:24:19
【问题描述】:

我在forge.laravel.com上开发申请,需要使用GuzzleHttp。

问题是我还没有注册域名myapplication.dev。

当我从客户端浏览网站时,我解决了这个问题,把它放在我的 windows 主机文件中:

myapplication.dev X.XX.XX.XXX

但不知不觉这不适用于来自服务器的请求。

这就是我调用 GuzzleHttp 的方式:

$client = new Client([
          'base_uri' => request()->getSchemeAndhttpHost(),
          'headers' => request()->header()
      ]);
      $name = $client->get('/example.getName?id=1')->getBody()->getContents();

我可以使用 Forge 强制将 myapplication.dev 重定向到我的应用程序吗?

谢谢

【问题讨论】:

    标签: laravel virtualhost hosts guzzle


    【解决方案1】:

    当然,你可以在 nginx 的配置中设置你的服务器的 ip 地址。

    listen 80;
    server_name THE_IP;
    root /var/www/html;  #the location of your root dir...
    

    https://www.linode.com/docs/web-servers/nginx/how-to-configure-nginx/

    看看服务器块。

    然后在你的 guzzle 客户端中指向一个 ip 而不是域。

    【讨论】:

    • 我使用 Forge.lavavel.com,当我尝试更改 NGINX 配置时出现此错误:在 0.0.0.0:80 上冲突的服务器名称“xxx.xxx.xxx.xxx”,被忽略跨度>
    • 这不是您想要的,但可能会有所帮助:另一种不同的方法是实现模拟处理程序。见docs.guzzlephp.org/en/stable/testing.html#mock-handler
    猜你喜欢
    • 2019-09-17
    • 2018-07-06
    • 2018-07-03
    • 1970-01-01
    • 2011-04-30
    • 2018-05-11
    • 2017-03-26
    • 2013-02-06
    • 1970-01-01
    相关资源
    最近更新 更多