request.setCharacterEncoding("iso8859-1");
response.setContentType("text/plain");
InputStream is = request.getInputStream();
logger.info("Content-Length长度---》"+request.getContentLength());
byte[] buf = new byte[request.getContentLength()];
logger.info("buf的长度"+buf.length);
int len = is.read(buf);
logger.info("len----------->"+len);
现在的问题是有时候接受的数据不全,查看log看到Content-Length与len 不相等,正常情况下Content-Length是等于len的,各位大侠帮助解决下.......

解决方案 »

  1.   

    read方法并不保证一次读完数据,你可以循环读直到得到-1这个返回值为止。不高兴写这个循环的话,可以考虑使用DataInputStream类提供的readFully()方法。
      

  2.   

    request.setCharacterEncoding("iso8859-1");
    response.setContentType("text/plain");
    InputStream is = request.getInputStream();
    logger.info("Content-Length长度---》"+request.getContentLength());
    byte[] buf = new byte[request.getContentLength()];
    logger.info("buf的长度"+buf.length);
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(buf);

      

  3.   

    DataInputStream dis = new DataInputStream(is);
    dis.readFully(buf);
    ----返回的是void  达不到想要的效果啊
      

  4.   

    magong 你的Q多少 可以加你Q聊下吗
      

  5.   

    嗯哪,这方法如果不读满buf是不返回的,你无须返回信息。
      

  6.   

    magong 你的Q多少 可以加你Q聊下吗 
      

  7.   

    用这样之后
    DataInputStream dis = new DataInputStream(is);
    dis.readFully(buf);
    下面该怎样继续
      

  8.   

    下面的代码就使用buf数组中的内容好了。