using System;
using System.Net;
using System.Text;
namespace HDL_ON.DAL.Server
{
public partial class HttpServerRequest
{
string RequestHttpsHost = "https://developer.hdlcontrol.com/";
///
/// 请求服务器方法
///
ResponsePack RequestHttps(string url, string dataStringJson, bool needAuthorization)
{
ResponsePack revertObj = new ResponsePack() { StateCode = "Self:NotData" };
var webClient = new WebClient();
#region
webClient.Headers.Add("CONTENT-TYPE", "application/json");
if (needAuthorization)
{
webClient.Headers.Add("Authorization", UserInfo.Current.LoginTokenString);
}
byte[] bytes = null;
try
{
bytes = webClient.UploadData(url, Encoding.UTF8.GetBytes(dataStringJson));
}
catch (Exception ex)
{
MainPage.Log($"http upload data error : {ex.Message}");
revertObj.StateCode = "Self:Net_Error";
revertObj.ErrorInfo_En = "Network anomaly";
revertObj.ErrorInfo_Zh = "网络异常";
}
try
{
if (bytes != null)
{
string responseString = Encoding.UTF8.GetString(bytes);
if (responseString != null)
{
revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
}
}
}
catch (Exception ex)
{
MainPage.Log($"http upload data error : {ex.Message}");
}
return revertObj;
#endregion
}
}
}