【问题标题】:Guzzle and dockerGuzzle 和码头工人
【发布时间】:2019-02-05 23:21:03
【问题描述】:

我使用 laravel 作为我的框架,并安装了护照和 guzzle。我正在尝试从服务器获取我正在开发的 iPhone 应用程序的密码授权令牌。这就是我为授权令牌调用 api 的方式

$http = new GuzzleHttp\Client;

$response = $http->post('http://your-app.com/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'username' => 'taylor@test',
        'password' => 'my-password',
        'scope' => '',
    ],
]);

return json_decode((string) $response->getBody(), true);

当我使用所有正确的数据调用它时,我会从控制台收到此错误。

GuzzleHttp\Exception\ConnectException: cURL error 7: 
Failed to connect to studious.test port 80: Connection refused (see 
http://curl.haxx.se/libcurl/c/libcurl-errors.html) in file /var/www/your-app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 185

我也在使用 Laradock 进行开发,并且我的 hosts 文件中有 your-app.com 和 www.your-app.com。从我的研究看来,这可能是由于某些 dns 内容而导致的错误。不知道这到底是怎么回事。

在我的主机文件中,我尝试在我的 url 中添加和不添加 www。

【问题讨论】:

  • 您找到解决方案了吗?
  • 我也有同样的问题。我几乎可以肯定它与 Docker 和网络有关,真烦人!有没有人找到解决方案?

标签: laravel docker guzzle laradock


【解决方案1】:

您需要将请求的url替换为http://{nameofservice}/oauth/token,例如http://nginx/oauth/token,那么它应该可以工作

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多