POST到Jersey REST服务获取错误415不支持的媒体类型我正在使用Jersey和Tomcat的JAX-RS Web应用程序。获取请求很好但是当我尝试发布JSON时,我得到HTTP状态415 - 不支持的媒体类型。这是我的简单HelloWorld.java:package service;import javax.ws.rs.*;@Path("hello")public class HelloWorld {
@GET
@Produces("text/plain")
public String get() {
return "hello world";
}
@POST
@Consumes("application/json")
public String post(JS input) {
return input.hello;
}
public static class JS {
public String hello;
}}这是我在Postman中尝试的请求(带有'application / json'标题):这是包含库的项目布局: 我在用:Java 7 x64泽西岛2.17Tomcat 7.0.62 x64谢谢!
3 回答

缥缈止盈
TA贡献2041条经验 获得超4个赞
检查您的REST调用contentType。它应该是contentType:'application / json',如果你将json数据传递给POJO类。
添加回答
举报
0/150
提交
取消