从客户端 传递大数据量的数据到服务器端,采用普通方式发送, 会出错:
@POST @Path("test") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_PLAIN) public String getTest(InputStream is, @Context HttpServletRequest request) throws Exception{ byte[] buf = new byte[is.available()]; is.read(buf); System.out.println("buf:"+new String(buf)); return ""; } // 客户端代码 StringBuilder ss = new StringBuilder(); for(int i=0;i<1000;i++){ ss.append("sssssssssss"); } //ss 是一个很长的字符串 ByteArrayInputStream bais = new ByteArrayInputStream(ss.toString().getBytes()); service.path("services").path("test").type(MediaType.APPLICATION_FORM_URLENCODED.entity(bais).post(String.class);
InputStream is, @Context HttpServletRequest request
entity(bais)
搞不懂 传送前 ss.toString().length() != 传送后 is.avaliable()
参考http://blog.youkuaiyun.com/heihei0923/archive/2009/11/09/4791910.aspx