关闭

How to retreive raw post data from HttpServletRequest in java

标签: requestpostraw
1009人阅读 评论(0) 收藏 举报

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();
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1166849次
    • 积分:9060
    • 等级:
    • 排名:第2036名
    • 原创:123篇
    • 转载:195篇
    • 译文:1篇
    • 评论:186条
    文章分类
    最新评论