1

Locally project runs fine. On the server getting this error while sending POST request to the POST route in Laravel 9 API.

"message": "The GET method is not supported for this route. Supported methods: POST."

My route from the api.php routes file:

Route::post('/userdata/create', [UserDataController::class, 'createAccount']);

My route from the routes list (from php artisan route:list):

POST       api/v1/userdata/create .......... Api\V1\UserDataController@createAccount

Tried:

php artisan cache:clear
php artisan route:cache
php artisan route:clear

Didn't fixed it yet.

Vadim
  • 469
  • 3
  • 13

4 Answers4

4

It happens cause you have forced your domain to HTTPS redirect and you are trying to use it as HTTP. Your domain settings redirect your request to HTTPS but not to POST method.

  • If you look for postman logs/console you will find redirection of HTTP POST request to HTTPS GET request

enter image description here

  • Hence Error response by your server of

enter image description here

0

The solution to that problem was actually very simple:

I needed to send POST request to "https" url, and i was sending it to "http" url.

Still strange that server was complaining that GET method is used...

Vadim
  • 469
  • 3
  • 13
0

This problem happened to me recently where I was using .com instead of .net

kittycatbytes
  • 995
  • 8
  • 14
0

that happen because laravel cannot return the error.

SOLUTION 1 :

you can use this inside your API post function :

try{
   // example we have name field
   $request->validate([
      'name' => ['required','string','max:255']
   ]);
   
   User::create([
      'name' => $request->name
   ]);

   return 'registered';
     
}catch(Exception $error){
   
   // your error from validation will appear here
   // dd($error->validator->messages());
   
}

SOLUTION 2 :

as alternative : I found another method here at this link

Anthony Kal
  • 2,729
  • 1
  • 20
  • 18