laravel - Guzzle 和 docker

标签 laravel docker guzzle laradock

我使用 laravel 作为我的框架,并安装了 Passport 和 guzzle。我正在尝试从服务器获取我正在开发的 iPhone 应用程序的密码授予 token 。这就是我为授予 token 调用 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 进行开发,我的主机文件中有 your-app.com 和 www.your-app.com。从我的研究看来,这可能是由于某些 dns 内容造成的错误。不知道这到底是怎么回事。

在我的主机文件中,我尝试将我的 url 与 www 放在一起。

最佳答案

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

关于laravel - Guzzle 和 docker ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52106756/

相关文章:

PHP Guzzle 客户端错误响应/错误请求 400 Google OAuth2 token

php - guzzlehttp 在 Laravel 项目上抛出错误 - strtolower() : Argument #1 ($string) must be of type string, int 给出

php - Guzzle - Elasticsearch - 批量 API

php - 如何在 laravel View 中添加图像?

docker - docker-compose问题:尝试创建/装入卷时权限被拒绝

php - 在 Laravel 中使用带有 LIKE 子句和可变列名称的 DB::select()

docker - 来自kubernetes集群的apt更新给出错误Clearsigned文件无效,得到 'NOSPLIT'(网络需要身份验证吗?)

docker - openshift使用uid 101运行所有容器,而不是从项目范围获取uid

laravel - 在 laravel 7 应用程序中添加了 jquery 引发错误

php - 行为 "Unrecognized options"