我尝试运行通行证'/ oauth / clients'方法来创建新的通行证的客户端,并得到
local.ERROR: cURL error 3: <url> malformed error
我愿意:
$app_root_url = config('app.url');
\Log::info('-1 REGISTER $app_root_url::');
\Log::info($app_root_url);
$headers = [
'content-type' => 'application/json',
'verify' => true,
];
$guzzleClient = new \GuzzleHttp\Client();
$url = '/oauth/clients';
$requestBody['name'] = $newUser->name;
$requestBody['redirect'] = $app_root_url . '/callback';
// $requestBody['Accept'] = 'application/json'; // Do I need this parameter ?
\Log::info('-2 REGISTER $requestBody::');
\Log::info($requestBody);
$request = $guzzleClient->post( $url, [
"headers" => $headers, // Do I need these params ?
'form_params' => $requestBody // ERROR REFERING THIS LINE
]);
$response = $request->send();
\Log::info('-3 REGISTER $response::');
\Log::info($response);
我看到的日志文件:
local.INFO: -1 REGISTER $app_root_url::
local.INFO: http://local-hostels3-backend-api.com
local.INFO: -2 REGISTER $requestBody::
local.INFO: array (
'name' => 'admin',
'redirect' => 'http://local-hostels3-backend-api.com/callback',
)
local.ERROR: cURL error 3: <url> malformed (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) {"exception":"[object] (GuzzleHttp\\Exception\\RequestException(code: 0): cURL error 3: <url> malformed (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) at /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:201)
[stacktrace]
#0 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(155): GuzzleHttp\\Handler\\CurlFactory::createRejection(Object(GuzzleHttp\\Handler\\EasyHandle), Array)
#1 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(105): GuzzleHttp\\Handler\\CurlFactory::finishError(Object(GuzzleHttp\\Handler\\CurlHandler), Object(GuzzleHttp\\Handler\\EasyHandle), Object(GuzzleHttp\\Handler\\CurlFactory))
#2 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(43): GuzzleHttp\\Handler\\CurlFactory::finish(Object(GuzzleHttp\\Handler\\CurlHandler), Object(GuzzleHttp\\Handler\\EasyHandle), Object(GuzzleHttp\\Handler\\CurlFactory))
#3 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(28): GuzzleHttp\\Handler\\CurlHandler->__invoke(Object(GuzzleHttp\\Psr7\\Request), Array)
#4 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(51): GuzzleHttp\\Handler\\Proxy::GuzzleHttp\\Handler\\{closure}(Object(GuzzleHttp\\Psr7\\Request), Array)
#5 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(66): GuzzleHttp\\Handler\\Proxy::GuzzleHttp\\Handler\\{closure}(Object(GuzzleHttp\\Psr7\\Request), Array)
#6 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Middleware.php(29): GuzzleHttp\\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\\Psr7\\Request), Array)
#7 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(70): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}(Object(GuzzleHttp\\Psr7\\Request), Array)
#8 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Middleware.php(59): GuzzleHttp\\RedirectMiddleware->__invoke(Object(GuzzleHttp\\Psr7\\Request), Array)
#9 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/HandlerStack.php(71): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}(Object(GuzzleHttp\\Psr7\\Request), Array)
#10 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Client.php(361): GuzzleHttp\\HandlerStack->__invoke(Object(GuzzleHttp\\Psr7\\Request), Array)
#11 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Client.php(163): GuzzleHttp\\Client->transfer(Object(GuzzleHttp\\Psr7\\Request), Array)
#12 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Client.php(183): GuzzleHttp\\Client->requestAsync('post', Object(GuzzleHttp\\Psr7\\Uri), Array)
#13 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/vendor/guzzlehttp/guzzle/src/Client.php(96): GuzzleHttp\\Client->request('post', '/oauth/clients', Array)
#14 /mnt/_work_sdb8/wwwroot/lar/hostels3-backend-api/app/Http/Controllers/AuthController.php(207): GuzzleHttp\\Client->__call('post', Array)
#15 [internal function]: App\\Http\\Controllers\\AuthController->register(Object(Illuminate\\Http\\Request))
在我的app / Providers / AuthServiceProvider.php中,我添加了护照路线定义:
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
...
"guzzlehttp/guzzle": "^6.5",
"laravel/framework": "^6.2",
"laravel/passport": "^8.1",
是什么引起了此错误以及如何纠正它?
谢谢!
似乎您的$url
变量只有路径部分缺少它必须定位的任何主机。