小编cha*_*333的帖子

Jersey 415不支持的媒体类型

我已经尝试了几个小时来纠正http错误,415 Unsupported Media Type但它仍然显示媒体不受支持的页面.我application/json在Postman中添加标题.

这是我的Java代码

package lostLove;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;  
import javax.ws.rs.POST;
import javax.ws.rs.Path;  
import javax.ws.rs.PathParam;  
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; 

import org.json.JSONObject;


@Path("/Story") 
public class Story {

      @POST
      @Consumes({"application/json"})
      @Produces(MediaType.APPLICATION_JSON)
    //  @Consumes(MediaType.APPLICATION_JSON)
    //  @Path("/Story") 
      public JSONObject sayJsonTextHello(JSONObject inputJsonObj) throws Exception {

        String input = (String) inputJsonObj.get("input");
        String output = "The input you sent is :" + input;
        JSONObject outputJsonObj = new JSONObject();
        outputJsonObj.put("output", output);

        return outputJsonObj;
      }

      @GET  
      @Produces(MediaType.TEXT_PLAIN)  

      public String sayPlainTextHello() { …
Run Code Online (Sandbox Code Playgroud)

java rest json jax-rs jersey

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

jax-rs ×1

jersey ×1

json ×1

rest ×1