I got exception PageNotFound: Request method 'POST' not supported
in my Spring Boot app.
This is my controller:
@RestController
public class LoginController {
UserWrapper userWrapper = new UserWrapper();
@RequestMapping(value = "/api/login", method = RequestMethod.POST, headers = "Content-type: application/*")
public @ResponseBody ResponseEntity getCredentials(@RequestBody UserDTO userDTO) {
User user = userWrapper.wrapUser(userDTO);
if (userDTO.getPassword().equals(user.getPassword())) {
return new ResponseEntity(HttpStatus.OK);
} else {
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
}
}
I am sending post request at localhost:8080/api/login
but it doesn't work. Have you got any idea?
EDIT:
UserDTO:
public class UserDTO implements Serializable {
private String email;
private String password;
//getters and setters
And json i send:
{
"email":"[email protected]",
"password":"password"
}
Spring declares all the supported request methods under an enum, RequestMethod, which specifies the standard GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE verbs. The Spring DispatcherServlet supports all of them by default, except OPTIONS and TRACE.
The spring boot exception Request method 'GET' not supported exists when the request method is not configured as 'GET' in one of the rest controller methods and is requested using the HTTP GET method. The request method is configured in annotation @RequestMapping.
I solved this issue by disabling the CSRF.
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With