java里不支持post请求_java – Spring Boot – 不支持请求方法’POST’

我的Spring Boot应用程序中不支持异常PageNotFound:Request方法’POST’.

这是我的控制器:

@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但它不起作用.你有什么想法吗?

编辑:

UserDTO:

public class UserDTO implements Serializable {

private String email;

private String password;

//getters and setters

和json我发送:

{

"email":"email@email.com",

"password":"password"

}

解决方法:

我通过禁用CSRF解决了这个问题.

@Configuration

class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override

protected void configure(HttpSecurity http) throws Exception {

http.csrf().disable();

}

}

标签:java,spring,spring-boot-2

来源: https://codeday.me/bug/20190716/1476506.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值