@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;
}
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)