Java – spring boot – the request method ‘post’ is not supported

Exception pagenotfound: request method 'post' is not supported in my spring boot application

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 sent an email request at localhost: 8080 / API / login, but it didn't work Do you have any ideas?

Edit:

UserDTO:

public class UserDTO implements Serializable {

private String email;
private String password;
//getters and setters

And JSON send me:

{
   "email":"email@email.com","password":"password"
}

Solution

I solved this problem by disabling CSRF

@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }
 }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>