laravel - "GET method is not supported for this route" even though it's a POST route
问题描述
I have a POST route in my Laravel application:
Route::post('/register-direct', 'Auth\RegisterController@direct')->name('register.direct');
Currently the method doesn't do anything but try to log the request:
public function direct(Request $request) {
logger()->info($request->all());
}
Since this route should be accessible from outside the domain, I disabled CSRF protection for it:
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'register-direct'
];
}
However, the strangest thing is happening. Even though it's a POST route, when I try to send the request from Postman to my remote site, I get the error:
The GET method is not supported for this route. Supported methods: POST.
From what I see, it is doing some sort of redirect to /register-direct
as a GET
route for some reason. The request never reaches the appropriate controller method (since the logging in the method never happens).
I suspect some middleware is the culprit, but the only middleware on this controller is the guest()
middleware. And when I disable this middleware, it doesn't change anything.
Additional info:
- there is no other route with the same name or URI
- when I send the POST request to localhost (instead of to my remote site) it works correctly
- the same error appears in Postman and if I try to submit this request from another domain
- I have tried moving the route from
web.php
toapi.php
and nothing changed - I have other routes in
api.php
that accept remote requests and work just fine
解决方案
推荐阅读
- mysql - 以十进制形式在数据库中存储百分比
- java - FirebaseRecyclerAdapter 不工作或显示任何数据
- c# - 如何禁用消息“您只能使用 Microsoft .NET Core 调试器...”?
- c# - 拍摄辅助显示器的屏幕截图时出现图像大小问题
- node.js - 从 Rust 使用 nodejs 库
- ios - 如何使 watchOS 上的 cloudKit 与 NSPersistentCloudKitContainer 一起工作
- python - 为什么 pandas.cut 将第一个元素归类为 NaN?
- kotlin - 函数中带有和不带有“挂起”lambda的“重载分辨率歧义”
- javascript - 没有任何 JS 访问令牌的 JWT 有效负载加密
- java - 无法通过代理连接到 websocket