Axios/XMLHttpRequest is sending GET instead of POST in production environment Axios/XMLHttpRequest is sending GET instead of POST in production environment laravel laravel

Axios/XMLHttpRequest is sending GET instead of POST in production environment


This question was also answered by me in the Larachat slack forum, and for others sake here is the answer for the next one with such a problem.

Just a little back story. In the chat we found out that it was receiving a 301 error which is a redirect error. I had the same error recently when posting to a url on a staging server, it was working fine locally but not on the staging server.

The problem appeared to be a slash at the end of the post url.

So posting to https://example.com/post/to/ will not work.

Removing the / and posting to https://example.com/post/to will work.


Just for info, I had the same thing - axios request was being redirected. For me though, it turned out to be some localization middleware causing the redirect!

I set up an alternative route in the Api routes file (again Laravel as in the question), bypassing that middleware (probably where the route should have gone in the first place!). All good now! Schoolboy error I guess!


I confirm the previous answer. And I had the same problem from local to production ambience.

The call to an endpoint like / api / user / store / might be redirect to / api / user / store with a 301 status code and this call was interpreted like a GET that obviously we cant reach (because it not in our route list). So it don't work.

A solution can be to work on Apache configuration (trim last slash) but I prefer to adapt my Axios call.