Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Laravel - Guzzle Request / cURL error 6: Could not resolve host

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);
});

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

Why am i getting this Error?

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

I am also using Homestead / Vagrant is this maybe a Problem that the host cant be resolved?

EDIT If i try this without the base_uri it works.

Route::get('guzzle/{username}', function($username) {
   $client = new GuzzleHttpClient();
    $response = $client->get("https://api.github.com/users/$username");
    dd($response);
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why are you calling $client->get->()->send()? In particular, why are you chaining the send() method at the end? The documentation does not append the send() method when demonstrating what seems to be the same action:

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

Also, did you consider the implications of this statement on the above-cited manual page?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...