李昊 4 years ago
parent
commit
12abfc28a6
1 changed files with 9 additions and 5 deletions
  1. 9 5
      GxPress/Infrastructure/GxPress.Common/Http/HttpClientHelper.cs

+ 9 - 5
GxPress/Infrastructure/GxPress.Common/Http/HttpClientHelper.cs

@@ -15,9 +15,10 @@ namespace GxPress.Common.Http
         /// <param name="url"></param>
         /// <param name="url"></param>
         /// <param name="headers"></param>
         /// <param name="headers"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static async Task<HttpResponseMessage> GetHeadersAsync(string url,Dictionary<string,string> headers)
+        public static async Task<HttpResponseMessage> GetHeadersAsync(string url, Dictionary<string, string> headers)
         {
         {
-            HttpClient httpClient = new HttpClient(); //http对象
+            var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator };
+            HttpClient httpClient = new HttpClient(httpClientHandler); //http对象
             //添加header
             //添加header
             foreach (var header in headers)
             foreach (var header in headers)
             {
             {
@@ -33,7 +34,8 @@ namespace GxPress.Common.Http
         /// <returns></returns>
         /// <returns></returns>
         public static async Task<byte[]> GetByteArrayAsync(string url)
         public static async Task<byte[]> GetByteArrayAsync(string url)
         {
         {
-            HttpClient httpClient = new HttpClient(); //http对象
+            var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator };
+            HttpClient httpClient = new HttpClient(httpClientHandler); //http对象
             var response = await httpClient.GetByteArrayAsync(url);
             var response = await httpClient.GetByteArrayAsync(url);
             return response;
             return response;
         }
         }
@@ -48,7 +50,8 @@ namespace GxPress.Common.Http
         public static async Task<HttpResponseMessage> PostAsync(string url, object jsonObj,
         public static async Task<HttpResponseMessage> PostAsync(string url, object jsonObj,
             Dictionary<string, string> headers = null)
             Dictionary<string, string> headers = null)
         {
         {
-            HttpClient httpClient = new HttpClient(); //http对象
+            var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator };
+            HttpClient httpClient = new HttpClient(httpClientHandler); //http对象
             if (headers != null)
             if (headers != null)
                 foreach (var header in headers)
                 foreach (var header in headers)
                 {
                 {
@@ -67,7 +70,8 @@ namespace GxPress.Common.Http
         /// <returns></returns>
         /// <returns></returns>
         public static async Task<HttpResponseMessage> DeleteAsync(string url, Dictionary<string, string> headers = null)
         public static async Task<HttpResponseMessage> DeleteAsync(string url, Dictionary<string, string> headers = null)
         {
         {
-            HttpClient httpClient = new HttpClient(); //http对象
+            var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator };
+            HttpClient httpClient = new HttpClient(httpClientHandler); //http对象
             if (headers != null)
             if (headers != null)
                 foreach (var header in headers)
                 foreach (var header in headers)
                 {
                 {