java request.getInputStream中文亂碼解決方案


請求時要指定為UTF-8,中文碼碼完美解決

/**
     *
     * 得到請求body字符串,一般用於content-type:application/json
     *
     */
    public static String getBodyString(HttpServletRequest request) {
        StringBuilder buffer = new StringBuilder("");
        try{
            request.setCharacterEncoding("UTF-8");
            BufferedReader reader=null;
            reader = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
            String line=null;
            while((line = reader.readLine())!=null){
                buffer.append(line);
            }
        }catch (IOException e) {
            LogerHelper.WebLog(e);
        }
        return buffer.toString();
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM