Guzzle post 对自己服务器的请求导致“404 Not Found”
Guzzle post request to own server resulted in a `404 Not Found`
我正在尝试登录我的 laravel 应用程序,该应用程序使用护照并将 guzzle
添加到 post 到我的 oath/token
路由,以便用户无需登录我不得不暴露我的 secret_key
但是我 运行 遇到了一个我似乎无法解决的错误
问题
我已经用 passport 更新了我的 laravel 应用程序,并在本地测试了我的后端,运行良好。在我将 laravel 应用程序部署到我的实时服务器测试环境后,我在尝试登录时开始遇到错误。
起初guzzle 无法验证我当前实时环境的SSL。所以我把验证变成了假。现在我开始得到一个不同的声明我的 url oath/token
路线是错误的。这是错误的,因为直接 posting 到我的 `oath/token' 似乎与 postmen 一起工作。
我还检查了路线是否存在 php artisan route:list
总结:guzzle 说 url 我 post 不存在,但确实存在
我的获取令牌功能
public function getToken(& $username, $password)
{
$http = new \GuzzleHttp\Client;
try {
$response = $http->post(config('services.passport.login_endpoint'), [
//'verify' => false,
'verify' => ( env( 'APP_ENV' ) === 'local' ) ? false : true,
'form_params' => [
'grant_type' => 'password',
'client_id' => config('services.passport.client_id'),
'client_secret' => config('services.passport.client_secret'),
'scope' => '',
'username' => $username,
'password' => $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 $e;
}
}
回应
GuzzleHttp\Exception\ClientException: Client error: `POST https: //my.domain.com/oauth/token` resulted in a `404 Not Found` response:
预期
每当 Guzzle
post 对我现有的路线有影响时,它 returns 来自我的 laravel 应用程序的响应。
添加调试
* Trying {my ip adres}...
* TCP_NODELAY set
* Connected to {mydomain} {my ip adres} port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=CH; L=Schaffhausen; O=Plesk; CN=Plesk; emailAddress=info@plesk.com
* start date: Feb 9 14: 54: 36 2020 GMT
* expire date: Feb 8 14: 54: 36 2021 GMT
* issuer: C=CH; L=Schaffhausen; O=Plesk; CN=Plesk; emailAddress=info@plesk.com
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /oauth/token HTTP/1.1
Host: {mydomain}
User-Agent: GuzzleHttp/6.3.3 curl/7.58.0 PHP/7.1.33
Content-Type: application/x-www-form-urlencoded
Content-Length: 144
* upload completely sent off: 144 out of 144 bytes
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Wed,
01 Apr 2020 17: 31: 26 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 266
< Connection: keep-alive
<
* Connection #0 to host {mydomain} left intact
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache Server at my.domain.com Port 443</address>
</body></html>
路线
| | POST | oauth/token | passport.token | Laravel\Passport\Http\Controllers\AccessTokenController@issueToken | throttle |
| | GET|HEAD | oauth/tokens | passport.tokens.index | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | passport.tokens.destroy | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@destroy | web,auth |
您是否尝试过在您配置的 login.endpoint 前面添加基数 url,例如:
$response = $http->post(config('app.url'). config('services.passport.login_endpoint'), [
...
]
]);
我在 post when I run php artisan serve
I can call 'base_uri' => "127.0.0.1:8000"
. So I added it to supervisor 到 运行 php artisan serve
中找到了解决方案,现在我可以调用我自己的服务器了。
显然我无法通过静态 PHP 调用我自己的服务器。
我正在尝试登录我的 laravel 应用程序,该应用程序使用护照并将 guzzle
添加到 post 到我的 oath/token
路由,以便用户无需登录我不得不暴露我的 secret_key
但是我 运行 遇到了一个我似乎无法解决的错误
问题
我已经用 passport 更新了我的 laravel 应用程序,并在本地测试了我的后端,运行良好。在我将 laravel 应用程序部署到我的实时服务器测试环境后,我在尝试登录时开始遇到错误。
起初guzzle 无法验证我当前实时环境的SSL。所以我把验证变成了假。现在我开始得到一个不同的声明我的 url oath/token
路线是错误的。这是错误的,因为直接 posting 到我的 `oath/token' 似乎与 postmen 一起工作。
我还检查了路线是否存在 php artisan route:list
总结:guzzle 说 url 我 post 不存在,但确实存在
我的获取令牌功能
public function getToken(& $username, $password)
{
$http = new \GuzzleHttp\Client;
try {
$response = $http->post(config('services.passport.login_endpoint'), [
//'verify' => false,
'verify' => ( env( 'APP_ENV' ) === 'local' ) ? false : true,
'form_params' => [
'grant_type' => 'password',
'client_id' => config('services.passport.client_id'),
'client_secret' => config('services.passport.client_secret'),
'scope' => '',
'username' => $username,
'password' => $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 $e;
}
}
回应
GuzzleHttp\Exception\ClientException: Client error: `POST https: //my.domain.com/oauth/token` resulted in a `404 Not Found` response:
预期
每当 Guzzle
post 对我现有的路线有影响时,它 returns 来自我的 laravel 应用程序的响应。
添加调试
* Trying {my ip adres}...
* TCP_NODELAY set
* Connected to {mydomain} {my ip adres} port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=CH; L=Schaffhausen; O=Plesk; CN=Plesk; emailAddress=info@plesk.com
* start date: Feb 9 14: 54: 36 2020 GMT
* expire date: Feb 8 14: 54: 36 2021 GMT
* issuer: C=CH; L=Schaffhausen; O=Plesk; CN=Plesk; emailAddress=info@plesk.com
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /oauth/token HTTP/1.1
Host: {mydomain}
User-Agent: GuzzleHttp/6.3.3 curl/7.58.0 PHP/7.1.33
Content-Type: application/x-www-form-urlencoded
Content-Length: 144
* upload completely sent off: 144 out of 144 bytes
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Wed,
01 Apr 2020 17: 31: 26 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 266
< Connection: keep-alive
<
* Connection #0 to host {mydomain} left intact
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache Server at my.domain.com Port 443</address>
</body></html>
路线
| | POST | oauth/token | passport.token | Laravel\Passport\Http\Controllers\AccessTokenController@issueToken | throttle |
| | GET|HEAD | oauth/tokens | passport.tokens.index | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | passport.tokens.destroy | Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController@destroy | web,auth |
您是否尝试过在您配置的 login.endpoint 前面添加基数 url,例如:
$response = $http->post(config('app.url'). config('services.passport.login_endpoint'), [
...
]
]);
我在 post when I run php artisan serve
I can call 'base_uri' => "127.0.0.1:8000"
. So I added it to supervisor 到 运行 php artisan serve
中找到了解决方案,现在我可以调用我自己的服务器了。
显然我无法通过静态 PHP 调用我自己的服务器。