瀏覽代碼

添加数据转发获取headers的工具方法

andy 1 年之前
父節點
當前提交
bbde1ddffc
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      src/main/java/com/scbfkj/uni/library/RequestUtil.java

+ 12 - 4
src/main/java/com/scbfkj/uni/library/RequestUtil.java

@@ -7,10 +7,7 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import java.time.LocalDateTime;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 public class RequestUtil {
     public final static String APP_ID = "appid";
@@ -57,6 +54,17 @@ public class RequestUtil {
         HttpServletRequest request = requestAttributes.getRequest();
         return request.getHeader(headerName);
     }
+    public static Map<String, String> getHeaders() {
+        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
+        HttpServletRequest request = requestAttributes.getRequest();
+        Enumeration<String> headerNames = request.getHeaderNames();
+        Map<String,String> headers = new HashMap<>();
+        while (headerNames.hasMoreElements()) {
+            String element = headerNames.nextElement();
+            headers.put(element,request.getHeader(element));
+        }
+        return headers;
+    }
 
     public static String getAppId() throws Exception {
         String session = getSessionId();