春风项目四线(合箱线、总装线)
懒羊羊
2024-01-18 162d0b2a887718585658404fdedc523d28cf659f
提交 | 用户 | 时间
fd2207 1 package com.jcdm.common.utils.http;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.nio.charset.StandardCharsets;
8 import javax.servlet.ServletRequest;
9 import org.apache.commons.lang3.exception.ExceptionUtils;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 /**
14  * 通用http工具封装
15  * 
16  * @author jc
17  */
18 public class HttpHelper
19 {
20     private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class);
21
22     public static String getBodyString(ServletRequest request)
23     {
24         StringBuilder sb = new StringBuilder();
25         BufferedReader reader = null;
26         try (InputStream inputStream = request.getInputStream())
27         {
28             reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
29             String line = "";
30             while ((line = reader.readLine()) != null)
31             {
32                 sb.append(line);
33             }
34         }
35         catch (IOException e)
36         {
37             LOGGER.warn("getBodyString出现问题!");
38         }
39         finally
40         {
41             if (reader != null)
42             {
43                 try
44                 {
45                     reader.close();
46                 }
47                 catch (IOException e)
48                 {
49                     LOGGER.error(ExceptionUtils.getMessage(e));
50                 }
51             }
52         }
53         return sb.toString();
54     }
55 }