获取xml信息并转为string

来源:互联网 发布:高速公路的数据 编辑:程序博客网 时间:2024/04/30 06:01
protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {        
        ServletInputStream ToUserName = request.getInputStream();
        final int BUFFER_SIZE = 8 * 1024;
        byte[] buffer = new byte[BUFFER_SIZE];
        int length = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        do {
            length = ToUserName.read(buffer);
            if (length > 0) {
                baos.write(buffer, 0, length);
            }
        } while (length * 2 == BUFFER_SIZE);

        byte[] ba = baos.toByteArray();
        String body = new String(ba, "utf-8");            
        System.out.println("body::::" + body);
    }

0 0
原创粉丝点击