Laravel-狂饮请求/cURL错误6:无法解析主机 [英] Laravel - Guzzle Request / cURL error 6: Could not resolve host

查看:451
本文介绍了Laravel-狂饮请求/cURL错误6:无法解析主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向Github API发出API请求只是为了进行测试.我在Laravel 5.1 APP上安装了最新的Guzzle版本("guzzle/guzzle":"^ 3.9"). 在我的routes.php中,我具有以下代码:

I try to make an API Request to the Github API just for testing. I installed the latest Guzzle Version ( "guzzle/guzzle": "^3.9" ) on my Laravel 5.1 APP. In my routes.php i have the following Code:

Route::get('guzzle/{username}', function($username) {
    $client = new Client([
        'base_uri' => 'https://api.github.com/users/',
    ]);
    $response = $client->get("/users/$username");
    dd($response);
});

如果我现在访问URL domain.dev/github/kayyyy,则会收到错误cURL error 6: Could not resolve host: users.

If i now visit the URL domain.dev/github/kayyyy i get the Error cURL error 6: Could not resolve host: users.

为什么会出现此错误?

如果我访问 https://api.github.com/users/kayyyy ,我可以参见json输出.

If i visit https://api.github.com/users/kayyyy i can see the json output.

我也在使用Homestead/Vagrant,这可能是主机无法解决的问题吗?

编辑 如果我在没有base_uri的情况下尝试了此方法,那么它将起作用.

EDIT If i try this without the base_uri it works.

Route::get('guzzle/{username}', function($username) {
   $client = new GuzzleHttp\Client();
    $response = $client->get("https://api.github.com/users/$username");
    dd($response);
});

推荐答案

好吧,我解决了这个愚蠢的错误. 我使用了new Client.

Okay i solved it, stupid mistake by me. I used new Client.

当然应该是new GuzzleHttp\Client

因为它只是在我的routes.php中进行测试,所以我没有Namespace

As it is just for testing in my routes.php i did not the Namespace

感谢大家的帮助.

这篇关于Laravel-狂饮请求/cURL错误6:无法解析主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆