test .
This commit is contained in:
@@ -6,13 +6,6 @@ using System.Text;
|
||||
|
||||
namespace HttpUtil
|
||||
{
|
||||
public class HikResponse<T>
|
||||
{
|
||||
public T Data { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string Msg { get; set; }
|
||||
}
|
||||
|
||||
public class HttpUtillib
|
||||
{
|
||||
/// <summary>
|
||||
@@ -50,7 +43,7 @@ namespace HttpUtil
|
||||
initRequest(header, uri, "", false);
|
||||
|
||||
// build web request object
|
||||
var sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(_isHttps ? "https://" : "http://").Append(_ip).Append(":").Append(_port.ToString()).Append(uri);
|
||||
|
||||
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sb.ToString());
|
||||
@@ -270,7 +263,8 @@ namespace HttpUtil
|
||||
// set remote certificate Validation auto pass
|
||||
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(remoteCertificateValidate);
|
||||
// FIX:修复不同.Net版对一些SecurityProtocolType枚举支持情况不一致导致编译失败等问题,这里统一使用数值
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | (SecurityProtocolType)3072 | (SecurityProtocolType)768 | (SecurityProtocolType)192;
|
||||
//(SecurityProtocolType)48 |
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768 | (SecurityProtocolType)192;
|
||||
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
}
|
||||
}
|
||||
@@ -383,11 +377,13 @@ namespace HttpUtil
|
||||
{
|
||||
sb.Append(kvp.Value);
|
||||
}
|
||||
|
||||
sb.Append("\n");
|
||||
if (sbSignHeader.Length > 0)
|
||||
{
|
||||
sbSignHeader.Append(",");
|
||||
}
|
||||
|
||||
sbSignHeader.Append(kvp.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,20 +49,21 @@ public class GainfoFacesController : ControllerBase
|
||||
var key = "27390082";
|
||||
var secret = "MLl7Dv7p5Pgc9XYI3r4O";
|
||||
|
||||
// HttpUtillib.SetPlatformInfo(key, secret, "10.32.0.10");
|
||||
// HttpUtillib.HttpPost(url, body, 15);
|
||||
HttpUtillib.SetPlatformInfo(key, secret, "10.32.0.10");
|
||||
var r = HttpUtillib.HttpPost(url, body, 15);
|
||||
return Encoding.UTF8.GetString(r);
|
||||
|
||||
var headers = InitRequest(url, body, key, secret);
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(headers["Accept"]));
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
foreach (var item in headers.Where(x => x.Key != "Accept").Where(x => x.Key != "Content-Type"))
|
||||
{
|
||||
content.Headers.Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
var r = await client.PostAsync(url, content);
|
||||
return await r.Content.ReadAsStringAsync();
|
||||
// var headers = InitRequest(url, body, key, secret);
|
||||
// client.DefaultRequestHeaders.Accept.Clear();
|
||||
// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(headers["Accept"]));
|
||||
// var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
// foreach (var item in headers.Where(x => x.Key != "Accept").Where(x => x.Key != "Content-Type"))
|
||||
// {
|
||||
// content.Headers.Add(item.Key, item.Value);
|
||||
// }
|
||||
//
|
||||
// var r = await client.PostAsync(url, content);
|
||||
// return await r.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> InitRequest(string url, string body, string key, string secret)
|
||||
|
||||
Reference in New Issue
Block a user