| | |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | |
| | | namespace HH.WCS.ZhongCeJinTan.util |
| | | { |
| | | public class HttpHelper |
| | | { |
| | | |
| | | /// <summary> |
| | | /// MD5加密 |
| | | /// </summary> |
| | | /// <param name="sInput"></param> |
| | | /// <returns></returns> |
| | | public static string GetMd5FromString(string sInput) |
| | | { |
| | | var lstData = Encoding.GetEncoding("utf-8").GetBytes(sInput); |
| | | var lstHash = new MD5CryptoServiceProvider().ComputeHash(lstData); |
| | | var result = new StringBuilder(32); |
| | | for (int i = 0; i < lstHash.Length; i++) |
| | | { |
| | | result.Append(lstHash[i].ToString("x2").ToUpper()); |
| | | } |
| | | return result.ToString(); |
| | | } |
| | | |
| | | public string WebPost(string url, string postData, string cotentType = "application/json") { |
| | | |
| | | //配置鉴权 |
| | | //var AppKey = Settings.AppKey; |
| | | //var AppSecret = Settings.AppSecret; |
| | | ////获取时间戳 |
| | | //var ReqTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); |
| | | ////var ReqTime = GetTimeStamp(DateTime.Now.AddHours(-8), 1, 2); |
| | | //LogHelper.Info($"加密前 AppKey={AppKey} AppSecret={AppSecret} ReqTime={ReqTime} "); |
| | | //LogHelper.Info($"地址:{url},内容:{postData}"); |
| | | //var ReqVerify = GetMd5FromString(AppKey + AppSecret + ReqTime); |
| | | //LogHelper.Info($"加密后 AppKey={AppKey} AppSecret={AppSecret} ReqTime={ReqTime} ReqVerify={ReqVerify} url={url} req={postData}"); |
| | | //request.Headers.Add("ReqTime", ReqTime.ToString()); |
| | | //request.Headers.Add("ReqVerify", ReqVerify); |
| | | //request.Headers.Add("AppKey", AppKey); |
| | | |
| | | |
| | | Console.WriteLine(url); |
| | | WebRequest request = WebRequest.Create(url); |
| | | request.Method = "POST"; |
| | |
| | | request.ContentLength = byteArray.Length; |
| | | request.Timeout = 6000; |
| | | |
| | | |
| | | |
| | | try { |
| | | Stream dataStream = request.GetRequestStream(); |
| | | dataStream.Write(byteArray, 0, byteArray.Length); |