问题描述
限时送ChatGPT账号..该项目在我的本地服务器上运行,没有错误.但是在将项目上传到服务器后,我得到了
The project is working on my local server without error. But after uploading the project to the server I am getting
此路由不支持 GET 方法.支持的方法:POST.
The GET method is not supported for this route. Supported methods: POST.
错误.我用的是 Laravel 6.0
error. I used Laravel 6.0
API.php:
Route::post('rates', 'ShippoController@rates');
控制器:
public function rates(Request $request){
$validatedData = $request->validate([
'email' => 'required|email',
'name' => 'required',
'token' => 'required',
]);
try{
$carts = Cart::whereToken($request->token)->get();
if (count($carts) == 0){
return response()->json([
'status' => 0,
'message' => 'Invalid cart token.',
], Response::HTTP_NOT_IMPLEMENTED);
}
...
return response()->json([
'status' => 1,
'data' => $data,
], Response::HTTP_OK);
}
catch (\Exception $e){
return response()->json([
'status' => 0,
'message' => $e->getMessage()
], Response::HTTP_BAD_GATEWAY);
}
}
推荐答案
您的问题是 http://canvas.safedevs/ 重定向到 https://canvas.safedevs/.发生重定向时,POST 将转换为 GET,并且发布数据丢失.
Your issue is that http://canvas.safedevs/ redirects to https://canvas.safedevs/. When a redirect occurs, the POST is converted to a GET and the post data lost.
将请求发送到端点的 HTTPS 版本,它应该可以正常工作.
Send the request to the HTTPS version of the endpoint and it should work fine.
Insomnia 显然具有禁用自动跟随重定向的功能,您可能会考虑打开.它会让您更好地了解此类问题.
Insomnia apparently has a feature to disable automatically following redirects, which you might consider turning on. It'll give you better visibility on issues like this.
这篇关于上传 Laravel 6.0 项目后,我得到“此路由不支持 GET 方法.支持的方法:POST."错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论