How to enable POST method on heroku server (for React app)? I am getting 405 method not allowed

房东的猫 提交于 2020-07-31 04:37:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!