skip to Main Content

I made a website on a local computer, after transferring it to the server and https API requests stopped working

routes/api.php

Route::post('/shop/search', SearchController::class);

call this url:

https://server.example/api/shop/search

Unit tests work for post requests , but requests from Postman or other utilities display an error { "message": "The GET method is not supported for route api/shop/search. Supported methods: POST." }

If I change in api.php to get method – it works.

Tried various solutions that I found on this topic, but still post requests are not processed over HTTPS.

2

Answers


  1. It is normal to get that error, when you make a call like this https://server.example/api/shop/search you are sending a GET request, and you define this route with POST request inside your API routes.

    Define the same route again but with GET method, it is normal to define the same route with different methods and each method is handled by different function inside your controller.

    Route::post('/shop/search', [SearchController::class, 'show']);
    Route::get('/shop/search', [SearchController::class, 'search']);
    
    Login or Signup to reply.
  2. In Postman, did you use the POST method or the GET method? If you used GET, that might be the error, because the route expects a POST method. Try changing the method in Postman, as shown in the image.

    Postman screen

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search