分支自 SuZhouGuanHong/TaiYuanTaiZhong

PCS
dengjunjie
2023-12-13 113d1d4262d8f9e78a9d92123713c41669ad6c87
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
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
 
namespace WIDESEA_Core.Utilities
{
    public class HttpManager
    {
        //public static Task<string> HttpPostAsync(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> headers = null)
        //{
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        //    request.Method = "POST";
        //    if (!string.IsNullOrEmpty(contentType))
        //    {
        //        request.ContentType = contentType;
        //    }
        //    if (headers != null)
        //    {
        //        foreach (var header in headers)
        //            request.Headers[header.Key] = header.Value;
        //    }
 
        //    try
        //    {
        //        byte[] bytes = Encoding.UTF8.GetBytes(postData ?? "");
        //        using (Stream sendStream = request.GetRequestStream())
        //        {
        //            sendStream.Write(bytes, 0, bytes.Length);
        //        }
 
        //        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        //        {
        //            Stream responseStream = response.GetResponseStream();
        //            StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
        //            return streamReader.ReadToEndAsync();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        return Task.FromResult(ex.Message);
        //    }
 
        //}
        //public static  Task<string> HttpGetAsync(string url, Dictionary<string, string> headers = null)
        //{
        //    try
        //    {
        //        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        //        if (headers != null)
        //        {
        //            foreach (var header in headers)
        //                request.Headers[header.Key] = header.Value;
        //        }
        //        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        //        {
        //            Stream responseStream = response.GetResponseStream();
        //            StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
        //            return streamReader.ReadToEndAsync();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        return Task.FromResult(ex.Message);
        //    }
        //}
    }
}