var data = new object[] { new { sn = SN, mac = Mac } };
var jobj = await Task.Run(() =>
{
try
{
using (HttpClient client = new HttpClient())
{
var url = Helper.GetAppSettings("SubmitAddress");
var json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
client.Timeout = TimeSpan.FromSeconds(5);
var result = client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json")).Result;
var ack = result.Content.ReadAsStringAsync().Result;
return JObject.Parse(ack);
}
}
catch (Exception ex)
{
return JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(new
{
code = 500,
msg = $"服务器错误,请核查数据提交地址,配置文件中“SubmitAddress”是否正确!\r\n{ex.Message}"
}));
}
});
loadCtrl.IsOpen = false;
var code = jobj["code"]?.Value<int>();
var msg = jobj["msg"]?.Value<string>();
|