[Vuejs]-How solve 404 error in axios post request in vue?

0👍

Based only on what I can see in your code, you are not telling axios the complete URL if I’m right about it, and you didn’t declare it somewhere else do this:

axios.post('yourdomain.com/api/authentication/login',params)

or

axios({
  url:'yourdomain.com/api/authentication/login',
  method:post,
  data:{}
})

or

in your main js file or any other file that you import axios (if you are sharing an instance of it globali):

axios({baseurl:'yourdomain.com'})

and then you don’t need to write the complete url everywhere and just insert the part you need like you are doing now and axios will join that address with the baseurl,I hope it helps

0👍

I guess the URL "api/authentication/login" might be wrong and the correct one would be "/api/authentication/login" that starts with /.

404 error means the resource referred by the URL does not exist. It happens when the server has deleted the resource, or you requested a wrong URL accidentally, or any wrong ways (e.g. GET vs POST)

To make sure if you were requesting to the correct URL (and to find where you’re requesting actually), open Google Chrome DevTools > Network panel. You might need reload.

The url api/xxx is relatively solved from the URL currently you are at. If you were at the page http://example.com/foo/bar, the requested URL becomes http://example.com/foo/bar/api/xxx. Starting with / means root so http://example.com/api/xxx.

This answer might help to understand the URL system: https://stackoverflow.com/a/21828923/3990900

👤Ginpei

-1👍

"404" means your API Endpoint is not found. You need to declare the location of your API Endpoint exactly. For example: http://localhost:8080/api/authentication/login.

Leave a comment