Guzzgle 无法往 docker-compose 搭建的环境发送请求么
$response = $this->client->post(env('LOGIN_URL'), [
'form_params' => [
'grant_type' => 'password',
'client_id' => env('PASSPORT_CLIENT_ID'),
'client_secret' => env('PASSPORT_SECRET'),
'username' => $phone,
'password' => $password,
'scope' => '*'
]
]);
$token = json_decode((string) $response->getBody(),true);
其中url为 localhost:8081/oauth/token
但是如果单独访问localhost:8081/oauth/token
则是可以的
LoginController.php Guzzgle报错:GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to localhost port 8081: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in file /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 200
PostMan 单独请求 localhost:8081/oauth/token
容器内请求
localhost
… 你应该请求在容器中宿主机
的ip 而不是localhost