using System; 
 | 
using System.Collections.Generic; 
 | 
using System.Linq; 
 | 
using System.Text; 
 | 
using System.Threading.Tasks; 
 | 
using System.Net.Http.Headers; 
 | 
using WIDESEA_Core.LogHelper; 
 | 
using System.Security.Cryptography; 
 | 
  
 | 
namespace WIDESEA_Core.Helper 
 | 
{ 
 | 
    public class HttpMesHelper 
 | 
    { 
 | 
        public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null) 
 | 
        { 
 | 
            string result = string.Empty; 
 | 
            DateTime beginDate = DateTime.Now; 
 | 
            try 
 | 
            { 
 | 
                using (HttpContent httpContent = new StringContent(requestJson)) 
 | 
                { 
 | 
                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); 
 | 
                     
 | 
                    using HttpClient httpClient = new HttpClient(); 
 | 
                    httpClient.Timeout = new TimeSpan(0, 0, 60); 
 | 
                    //正式 
 | 
                    string authorization = "AppKey 1830415116987195392"; 
 | 
                    //测试 
 | 
                    //string authorization = "AppKey 1773317109539201024"; 
 | 
  
 | 
  
 | 
                    headers = new Dictionary<string, string> 
 | 
                    { 
 | 
                        { "Authorization", authorization }, 
 | 
                        //正式 
 | 
                        { "Site_tenant_id", "0dc2d164-8a62-417e-8a00-808007464feb" } 
 | 
                        //测试 
 | 
                        //{ "Site_tenant_id", "ced19269-2b83-4577-be43-8cc2f700251e" } 
 | 
                    }; 
 | 
                    if (headers != null) 
 | 
                    { 
 | 
                        foreach (var header in headers) 
 | 
                            httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); 
 | 
                    } 
 | 
                    HttpResponseMessage responseMessage = httpClient.PostAsync(serviceAddress, httpContent).Result; 
 | 
                    result = responseMessage.Content.ReadAsStringAsync().Result; 
 | 
                } 
 | 
                return result; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                throw new Exception(e.Message); 
 | 
            } 
 | 
            finally 
 | 
            { 
 | 
                Logger.Add(serviceAddress, requestJson == null ? "" : requestJson, result, beginDate); 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
} 
 |