Browse Source

OkHttpUtils透传header

lirong 2 years ago
parent
commit
19514e8ce6

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectUtil.java

@@ -118,7 +118,7 @@ public class RedirectUtil {
                 else
                 {
 //                    Map<String, String> map = JSONObject.parseObject(postString, new TypeReference<Map<String, String>>() {});
-                    resultString[0] = OkHttpUtils.builder().url(url).post(false, postString).sync();
+                    resultString[0] = OkHttpUtils.builder().url(url).post(false, postString,request).sync();
 
 //                    resultString[0] = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null,request);
                 }

+ 11 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/OkHttpUtils.java

@@ -7,7 +7,9 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSocketFactory;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
+import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.net.URLEncoder;
 import java.security.SecureRandom;
 import java.security.cert.X509Certificate;
@@ -16,7 +18,6 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
-import java.lang.reflect.Field;
 
 
 /**
@@ -213,7 +214,7 @@ public class OkHttpUtils {
      *                   false等于普通的表单提交
      * @return
      */
-    public OkHttpUtils post(boolean isJsonPost,String paramMap) {
+    public OkHttpUtils post(boolean isJsonPost,String paramMap, HttpServletRequest httpServletRequest) {
         RequestBody requestBody;
         if (isJsonPost) {
             String json = "";
@@ -230,7 +231,14 @@ public class OkHttpUtils {
 //            }
 //            requestBody = formBody.build();
         }
-        request = new Request.Builder().post(requestBody).url(url);
+        Request.Builder request2 = new Request.Builder();
+        if (httpServletRequest != null) {
+            String authorization = httpServletRequest.getHeader("Authorization");
+            if (authorization != null) {
+                request2.header("Authorization",authorization);
+            }
+        }
+        request = request2.post(requestBody).url(url);
         return this;
     }