【发布时间】:2020-01-18 10:55:40
【问题描述】:
我在我的 Laravel 应用程序中使用 Guzzle 向 /oauth/token/ 发出请求作为登录请求,并看到连接被拒绝
我的自定义控制器中的代码是:
public function login(Request $request)
{
$http = new \GuzzleHttp\Client();
try {
$response = $http->post("https://mixapp.test/oauth/token/", [
'form_params' => [
'grant_type' => 'password',
'client_id' => config('services.passport.client_id'),
'client_secret' => config('services.passport.client_secret'),
'username' => $request->username,
'password' => $request->password,
]
]);
return $response->getBody();
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
if ($e->getCode() === 400) {
return response()->json('Invalid Request. Please enter a username or a password.', $e->getCode());
} else if ($e->getCode() === 401) {
return response()->json('Your credentials are incorrect. Please try again', $e->getCode());
}
return response()->json('Something went wrong on the server.', $e->getCode());
}
}
而且错误似乎是:
local.ERROR:cURL 错误 7:无法连接到 mixapp.test 端口 443:连接被拒绝(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html){“异常”:“[对象](GuzzleHttp\Exception\ConnectException(代码:0): cURL 错误 7:无法连接到 mixapp.test 端口 443:连接被拒绝
两者都在 https 上,我正在使用 laravel 代客。
【问题讨论】:
-
您是否可以使用 curl 或某些 REST 扩展手动发布到该地址?
-
是的,当我通过邮递员直接到达该端点时工作正常。
标签: php laravel curl guzzle laravel-valet