servlet - 获取 post body 体 (用流读取为空的问题)

https://blog.csdn.net/x6582026/article/details/51833819

其中:IOUtils.toString 源码为:

  public static void copy(InputStream input, Writer output, String encoding)
        throws IOException
    {
        if(encoding == null)
        {
            copy(input, output);
        } else
        {
            InputStreamReader in = new InputStreamReader(input, encoding);
            copy(((Reader) (in)), output);
        }
    }

    public static int copy(Reader input, Writer output)
        throws IOException
    {
        char buffer[] = new char[4096];
        int count = 0;
        for(int n = 0; -1 != (n = input.read(buffer));)
        {
            output.write(buffer, 0, n);
            count += n;
        }

        return count;
    }

 。

posted on 2018-05-23 12:29  TrustNature  阅读(31)  评论(0)    收藏  举报