【问题标题】:Laravel Guzzle error -- cURL error 7: Failed connect to api.github.com:80; Connection timed outLaravel Guzzle 错误 -- cURL 错误 7: 无法连接到 api.github.com:80;连接超时
【发布时间】:2015-02-13 02:07:06
【问题描述】:

我正在尝试通过 laravel 中的 http 请求获取 github 用户详细信息。

我为此使用包 Guzzle。 我的控制器如下所示,

 public function apiProject()
 {
    $client = new \GuzzleHttp\Client();
    $response = $client->get('http://api.github.com/users/jishadp369');
    dd($response->getBody());
 }

当我在浏览器中指向路线时,浏览器会加载一些时间并抛出类似

的错误
cURL error 7: Failed connect to api.github.com:80; Connection timed out 

我在终端中尝试使用 curl 我可以很好地得到结果。

在 Firebug->Net 中:它显示 500 Internal server error,

我该如何解决这个问题。 ?

谢谢

【问题讨论】:

    标签: curl laravel-4 github-api guzzle


    【解决方案1】:
        $client = new GuzzleHttp\Client();
        $response = $client->get('http://guzzlephp.org');
        $res = $client->get('https://api.github.com/users/jishadp369');
        echo $res->getStatusCode();
        // "200"
        echo $res->getHeader('content-type');
        // 'application/json; charset=utf8'
        echo $res->getBody();
        // {"type":"User"...'
        var_export($res->json());
    

    // 输出JSON解码数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 2018-08-01
      • 2021-05-23
      • 2017-11-09
      • 2023-03-26
      • 2010-11-26
      • 1970-01-01
      相关资源
      最近更新 更多