提交 | 用户 | age
|
826b66
|
1 |
package com.hx.util; |
C |
2 |
|
|
3 |
import org.apache.commons.io.IOUtils; |
|
4 |
|
|
5 |
import javax.servlet.http.HttpServletRequest; |
|
6 |
import java.io.BufferedReader; |
|
7 |
import java.io.IOException; |
|
8 |
import java.util.Enumeration; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.Map; |
|
11 |
|
|
12 |
/** HttpServletRequestUtil 获取请求中的body |
|
13 |
* @author wangrenhuang |
|
14 |
* @Date 2021-10-19 |
|
15 |
*/ |
|
16 |
public class HttpServletRequestUtil { |
|
17 |
|
|
18 |
/** |
|
19 |
* 获取bady |
|
20 |
* */ |
|
21 |
public static String getBody(HttpServletRequest request) { |
|
22 |
String wxMsgXml = null; |
|
23 |
if(request == null){ |
|
24 |
return wxMsgXml; |
|
25 |
} |
|
26 |
try{ |
|
27 |
wxMsgXml = IOUtils.toString(request.getInputStream(), |
|
28 |
"utf-8"); |
|
29 |
return wxMsgXml; |
|
30 |
}catch (Exception e){ |
|
31 |
wxMsgXml = null; |
|
32 |
} |
|
33 |
return wxMsgXml; |
|
34 |
} |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* |
|
39 |
* 获取请求头 |
|
40 |
* */ |
|
41 |
public static Map<String,String> getHeader(HttpServletRequest request) { |
|
42 |
Enumeration<String> enumeration = request.getHeaderNames(); |
|
43 |
Map<String,String> map = new HashMap<>(16); |
|
44 |
StringBuffer headers = new StringBuffer(); |
|
45 |
while (enumeration.hasMoreElements()) { |
|
46 |
String name = enumeration.nextElement(); |
|
47 |
String value = request.getHeader(name); |
|
48 |
map.put(name,value); |
|
49 |
} |
|
50 |
|
|
51 |
return map; |
|
52 |
} |
|
53 |
} |