删除不要的代码
This commit is contained in:
@@ -16,74 +16,12 @@ namespace WMS.Web.Core.Help
|
||||
{
|
||||
public class HttpClientHelp
|
||||
{
|
||||
private HttpOptions _options;
|
||||
private ILogger<HttpClientHelp> _logger;
|
||||
|
||||
public HttpClientHelp(IOptions<HttpOptions> options, ILogger<HttpClientHelp> logger)
|
||||
public HttpClientHelp(ILogger<HttpClientHelp> logger)
|
||||
{
|
||||
this._options = options?.Value;
|
||||
this._logger = logger;
|
||||
}
|
||||
public string PostHttp(string url, JsonObject reqData, bool isHaveCookie = false, string cookieValue = "", string appSecret = "")
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
HMACSHA1 hmacsha1 = new HMACSHA1();
|
||||
if (!string.IsNullOrEmpty(appSecret))
|
||||
{
|
||||
byte[] secret = Encoding.UTF8.GetBytes(appSecret);
|
||||
hmacsha1.Key = secret;
|
||||
}
|
||||
byte[] dataBuffer = Encoding.UTF8.GetBytes(reqData.ToString());
|
||||
byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
|
||||
|
||||
int contentLength = dataBuffer.Length;
|
||||
string rawHmac = Convert.ToBase64String(hashBytes);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/json; charset=utf-8";
|
||||
request.ContentLength = contentLength;
|
||||
request.Accept = "application/json; charset=utf-8";
|
||||
request.Headers.Add("Content-Signature", "HMAC-SHA1 " + rawHmac);
|
||||
if (isHaveCookie)
|
||||
{
|
||||
var cook = new Cookie();
|
||||
cook.Domain = _options.Url;
|
||||
cook.Name = "PHPSESSID";
|
||||
cook.Value = cookieValue;
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cook);
|
||||
}
|
||||
|
||||
Stream writer;
|
||||
try
|
||||
{
|
||||
writer = request.GetRequestStream();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
writer = null;
|
||||
Console.WriteLine("链接单点错误异常:" + ex.ToString());
|
||||
}
|
||||
writer.Write(dataBuffer, 0, dataBuffer.Length);
|
||||
writer.Close();
|
||||
|
||||
Stream responseStream;
|
||||
try
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
responseStream = response.GetResponseStream();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStream = null;
|
||||
//WriteLog("服务器异常" + ex.Message);
|
||||
}
|
||||
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
|
||||
|
||||
string respData = streamReader.ReadToEnd();
|
||||
responseStream.Close();
|
||||
return respData;
|
||||
}
|
||||
}
|
||||
|
||||
public string PostHttp(string url, LoginAuthorizeRequest reqData)
|
||||
{
|
||||
@@ -201,142 +139,6 @@ namespace WMS.Web.Core.Help
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public string PostHttpNoData(string url, string cookieValue = "")
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/json; charset=utf-8";
|
||||
request.Accept = "application/json; charset=utf-8";
|
||||
if (!string.IsNullOrEmpty(cookieValue))
|
||||
{
|
||||
var cook = new Cookie();
|
||||
cook.Domain = _options.Url;
|
||||
cook.Name = "PHPSESSID";
|
||||
cook.Value = cookieValue;
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cook);
|
||||
}
|
||||
|
||||
Stream writer;
|
||||
try
|
||||
{
|
||||
writer = request.GetRequestStream();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
writer = null;
|
||||
Console.WriteLine("链接单点错误异常:" + ex.ToString());
|
||||
}
|
||||
writer.Close();
|
||||
|
||||
Stream responseStream;
|
||||
try
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
responseStream = response.GetResponseStream();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStream = null;
|
||||
//WriteLog("服务器异常" + ex.Message);
|
||||
}
|
||||
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
|
||||
|
||||
string respData = streamReader.ReadToEnd();
|
||||
responseStream.Close();
|
||||
return respData;
|
||||
}
|
||||
|
||||
public string GetHttp(string url, bool isHaveCookie = false, string cookieValue = "")
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
HMACSHA1 hmacsha1 = new HMACSHA1();
|
||||
|
||||
request.Method = "Get";
|
||||
request.ContentType = "application/json; charset=utf-8";
|
||||
request.Accept = "application/json; charset=utf-8";
|
||||
if (isHaveCookie)
|
||||
{
|
||||
var cook = new Cookie();
|
||||
cook.Domain = _options.Url;
|
||||
cook.Name = "PHPSESSID";
|
||||
cook.Value = cookieValue;
|
||||
request.CookieContainer = new CookieContainer();
|
||||
request.CookieContainer.Add(cook);
|
||||
}
|
||||
|
||||
Stream writer;
|
||||
try
|
||||
{
|
||||
writer = request.GetRequestStream();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
writer = null;
|
||||
//WriteLog("连接服务器异常");
|
||||
}
|
||||
|
||||
Stream responseStream;
|
||||
try
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
responseStream = response.GetResponseStream();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseStream = null;
|
||||
//WriteLog("服务器异常" + ex.Message);
|
||||
}
|
||||
StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
|
||||
|
||||
string respData = streamReader.ReadToEnd();
|
||||
responseStream.Close();
|
||||
return respData;
|
||||
}
|
||||
|
||||
|
||||
private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public static long CurrentTimeMillis()
|
||||
{
|
||||
return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<JsonValue> Post(string url, string param, string token)
|
||||
{
|
||||
HttpClient _client = new HttpClient();
|
||||
//读取返回消息
|
||||
string res = string.Empty;
|
||||
try
|
||||
{
|
||||
//填充formData
|
||||
if (param == null) param = "";
|
||||
HttpContent hc = new StringContent(param, Encoding.UTF8)
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
ContentType = new MediaTypeHeaderValue("application/json")//application/x-www-form-urlencoded
|
||||
}
|
||||
};
|
||||
_client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
|
||||
var responseMessage = _client.PostAsync(url, hc).Result;
|
||||
var msg = await responseMessage.Content.ReadAsStringAsync();
|
||||
if (msg.Equals(""))
|
||||
return null;
|
||||
else
|
||||
return JsonObject.Parse(msg);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Help
|
||||
{
|
||||
public class HttpOptions
|
||||
{
|
||||
public string Url { get; set; }
|
||||
|
||||
public string K3Url { get; set; }
|
||||
public string K3UrlLogin { get; set; }
|
||||
public bool K3Enable { get; set; } = false;
|
||||
|
||||
public string EspUrl { get; set; }
|
||||
|
||||
public string EspAppId { get; set; }
|
||||
public string EspAppSecret { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user