gpt4 book ai didi

php - Laravel - Guzzle 请求/cURL 错误 6 : Could not resolve host

转载 作者:可可西里 更新时间:2023-11-01 00:05:08 27 4
gpt4 key购买 nike

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

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

为什么会出现此错误?

如果我访问https://api.github.com/users/kayyyy我可以看到 json 输出。

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

编辑如果我在没有 base_uri 的情况下尝试这样做,它会起作用。

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

最佳答案

为什么要调用 $client->get->()->send()?特别是,为什么要在最后链接 send() 方法?在演示看似相同的操作时,文档没有附加 send() 方法:

http://guzzle.readthedocs.org/en/latest/quickstart.html#creating-a-client

此外,您是否考虑过上述手册页中此声明的含义?

When a relative URI is provided to a client, the client will combine the base URI with the relative URI using the rules described in RFC 3986, section 2.

关于php - Laravel - Guzzle 请求/cURL 错误 6 : Could not resolve host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31923397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com