问题
I am getting 405 method not allowed. I am using axios.post for login. The form is taking input username and password and post to get authenticate. But POST method not allowed at heroku error in console.
Please help me to let me know how to enable POST method on heroku. or any solution.
Thanks in advanceenter image description here
回答1:
This is an axios post example:
axios.post("test/test", {userName:'..', password:'..'}).then((result) => onSuccess(result.data), (error) => onError(error));
If you are using spring-boot with Java you probably have a CORS problem. Try to put in your endpoint:
@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})
Replace "http://localhost:3000" with your localhost url if you need it. This is an example:
@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})
@RequestMapping(value = "/test", method = RequestMethod.POST)
ResponseEntity<HttpStatus> testLoginUser(@RequestBody DTO testDto) throws TestException {
//Do Something..
}
I don't know how the server is implemented, so: check if you have a CrossOrigin problem or if you have a security problem with your endpoints.
来源:https://stackoverflow.com/questions/50970961/how-to-enable-post-method-on-heroku-server-for-react-app-i-am-getting-405-met