HttpServletRequest gets the body of the post in utf-8 encoding

    public static String getRequestBody(HttpServletRequest request)
    {
    
    
        InputStream is = null;
        try
        {
    
    
            is = request.getInputStream();
            StringBuilder sb = new StringBuilder();
            byte[] b = new byte[4096];
            for (int n; (n = is.read(b)) != -1;)
            {
    
    
                sb.append(new String(b, 0, n,"utf-8"));
            }
            return sb.toString();
        }
        catch (IOException e)
        {
    
    
            e.printStackTrace();
        }
        finally
        {
    
    
            if (null != is)
            {
    
    
                try
                {
    
    
                    is.close();
                }
                catch (IOException e)
                {
    
    
                    e.printStackTrace();
                }
            }
        }
        return "";
    }

Guess you like

Origin blog.csdn.net/qsyjrz206/article/details/109694637