Spring Boot-请求方法'POST'不支持 [英] Spring Boot - Request method 'POST' not supported
本文介绍了Spring Boot-请求方法'POST'不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Spring Boot应用程序中出现异常PageNotFound: Request method 'POST' not supported
.
I got exception PageNotFound: Request method 'POST' not supported
in my Spring Boot app.
这是我的控制者:
@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);
}
}
}
我正在localhost:8080/api/login
发送发帖请求,但不起作用.你有什么主意吗?
I am sending post request at localhost:8080/api/login
but it doesn't work. Have you got any idea?
UserDTO:
public class UserDTO implements Serializable {
private String email;
private String password;
//getters and setters
我发送的是json:
{
"email":"email@email.com",
"password":"password"
}
推荐答案
我通过禁用CSRF解决了这个问题.
I solved this issue by disabling the CSRF.
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
这篇关于Spring Boot-请求方法'POST'不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文