茶爸爸(微信:benyzhous) 的专栏

坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活。

How to retreive raw post data from HttpServletRequest in java

public static String getPostData(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();
    try {
        BufferedReader reader = req.getReader();
        reader.mark(10000);

        String line;
        do {
            line = reader.readLine();
            sb.append(line).append("\n");
        } while (line != null);
        reader.reset();
        // do NOT close the reader here, or you won't be able to get the post data twice
    } catch(IOException e) {
        logger.warn("getPostData couldn't.. get the post data", e);  // This has happened if the request's reader is closed    
    }

    return sb.toString();
}
阅读更多
文章标签: request post raw
上一篇学习老外用webstorm开发nodejs的技巧--代码提示DefinitelyTyped
下一篇MongoDB shell操作
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭