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

前端 未结 1 639
梦谈多话
梦谈多话 2021-01-26 06:58

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 a

相关标签:
1条回答
  • 2021-01-26 07:43

    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.

    0 讨论(0)
提交回复
热议问题