HTTP 状态 415 - 请求实体的格式不受支持
2022-09-02 05:30:09
我正在开发java restful Web服务。我让它为GET请求工作,但POST请求不起作用。我的控制器类是 。到目前为止,我已经做了这些:RestController
@RequestMapping(value = "/api/signup", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public long signUp(@ModelAttribute ApiMemberModel apiMember) {
memberService = new MemberDetailsService();
Member m = memberService.createMember(apiMember.getUsername(), apiMember.getPassword(), apiMember.getEmail(), "");
return m.getId();
}
还尝试了 RequestBody 而不是 ModelAttribute。
我使用Postman扩展来发送POST请求。例如:
{
"username": "asd",
"password": "sfsdg",
"email": "sdfdsf@fdsfkg.com"
}
但是我得到错误:
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
我做错了什么?模型类为:
public class ApiMemberModel {
private String username;
private String password;
private String email;
public ApiMemberModel(String username, String password, String email) {
this.username = username;
this.password = password;
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}