Topuino_Client_Windows/PublicComm.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2022-06-10 18:51:48 +08:00
using System;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Topuino_Client_Windows
{
internal class PublicComm
{
private HttpClient client = new HttpClient();
private int errorCount = 0;
public async void Post(Dictionary<string, string> data)
{
try
{
HttpContent content = new FormUrlEncodedContent(data);
2022-06-14 20:43:29 +08:00
HttpResponseMessage response = await client.PostAsync("https://iot.vvzero.com/topuino/putdata", content);
2022-06-10 18:51:48 +08:00
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
PublicCommResponse? respData = JsonConvert.DeserializeObject<PublicCommResponse>(responseBody);
if (respData == null || respData.CODE != 0)
{
throw new Exception();
}
errorCount = 0;
}
catch
{
errorCount++;
if (errorCount > 5)
{
// TODO
}
}
}
}
internal class PublicCommResponse
{
public int CODE;
}
}