操控平台后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
764 B

using Admin.Bodk.Device;
using Newtonsoft.Json;
namespace Admin.NET.Core.Service;
public class ApiService
{
private readonly HttpClient _httpClient;
public ApiService()
{
_httpClient = new HttpClient();
}
public async Task<ResultData> GetApiResponseAsync(string url)
{
HttpResponseMessage response = await _httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ResultData>(responseBody);
if (result.IsSuccess)
{
return result;
}
else
{
throw Oops.Oh(result.Message);
}
}
}