当前位置: 代码迷 >> Java Web开发 >> jersey POST 方法报错(MediaType出错),大家用过的知道是什么原因吗?该怎么处理
  详细解决方案

jersey POST 方法报错(MediaType出错),大家用过的知道是什么原因吗?该怎么处理

热度:504   发布时间:2016-04-17 11:10:31.0
jersey POST 方法报错(MediaType出错),大家用过的知道是什么原因吗?
Java code
    @POST      @Path("test_post4")    @Consumes("application/x-www-form-urlencoded")     @Produces("text/plain")      public String getTest22222(InputStream is, @Context HttpServletRequest request) throws Exception{          byte[] buf = new byte[is.available()];          is.read(buf);          System.out.println("buf:"+new String(buf));          String result;           result= "--------"+request.getContextPath();                return result;      }  

Java code
    public static void main(String[] args) throws URISyntaxException {        // TODO Auto-generated method stub            URI u = new URI("http://localhost:8088/getstart/test_post4");        System.out.println(u);        Client client=Client.create();;        WebResource resource = client.resource(u);             String buf = "inputstream content.";          ByteArrayInputStream bais = new ByteArrayInputStream(buf.getBytes());          String result = resource.entity(bais).post(String.class);          System.out.println(result);      }


报错如下
Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8088/getstart/test_post4 returned a response status of 415 Unsupported Media Type
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:676)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:553)
at com.ibm.crl.iot.rest.spectrum.clientTest.main(clientTest.java:47)


------解决方案--------------------
你说的和这人说的正相反呢http://blog.csdn.net/heihei0923/article/details/4791910
------解决方案--------------------
这个报错信息写的很清楚了嘛
  相关解决方案