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

前端 未结 4 1476
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 22:50

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

相关标签:
4条回答
  • 2021-01-20 23:36

    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.

    0 讨论(0)
  • 2021-01-20 23:37

    Actually a variable interpolation is not possible within single quotes. This means that you currently are calling users/$username and the $username variable gets not replaced with its value.

    In order to get it, you should use it in one of the following ways:

    $response = $client->get("users/$username")->send();
    $response = $client->get('users/' . $username)->send();
    

    I personally prefer the second one as it is assumed to be faster.

    0 讨论(0)
  • 2021-01-20 23:42

    Thanks to Paratron https://github.com/googleapis/google-api-php-client/issues/1184#issuecomment-355295789 In my case, on cakephp 3.8 & docker 19.03.5, I was facing curl error due to some network issue. I restarted my cake-server docker container, & it worked like a charm.

    0 讨论(0)
  • 2021-01-20 23:44

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

    And it should be of course new GuzzleHttp\Client

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

    Thanks for your help everybody.

    0 讨论(0)
提交回复
热议问题