1
wangxinhui
2025-06-10 2779947fe07c41250237437365f367b5a78a03b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 HttpQmsHelper
    {
        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 1930944618148245504";
                    //测试
                    string authorization = "AppKey 1930944618148245504";
 
 
                    headers = new Dictionary<string, string>
                    {
                        { "Authorization", authorization },
                        //正式
                        //{ "Site_tenant_id", "6ec60d66-b08e-4ff3-90fa-57748053f79b" }
                        //测试
                        { "Site_tenant_id", "6ec60d66-b08e-4ff3-90fa-57748053f79b" }
                    };
                    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);
            }
        }
    }
}