其他分享
首页 > 其他分享> > HttpServletRequest request 请求中文转换

HttpServletRequest request 请求中文转换

作者:互联网

/**  
 *  request转字符串
 * @param request
 * @param charset 编码格式 (UTF-8)
 * @return
 * @see [类、类#方法、类#成员]
 */
public static String parseRequst(HttpServletRequest request,String charset){
    String body = "";
    try {
        ServletInputStream inputStream = request.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,charset));
        while(true){
            String info = br.readLine();
            if(info == null){
                break;
            }
            if(body == null || "".equals(body)){
                body = info;
            }else{
                body += info;
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return body;
}

标签:HttpServletRequest,body,中文,String,charset,request,info,br
来源: https://www.cnblogs.com/yuangyuan/p/16449577.html