using System; using System.Net.Http; using System.Threading.Tasks; using UnityEngine; namespace Ragdoll { public class RdHttpClient : ScriptSingleton { private readonly HttpClient _httpClient; public RdHttpClient() { _httpClient = new HttpClient(); _httpClient.Timeout = new TimeSpan(0, 0, 0, 5, 0); } public async Task PostAsync(string url, string content) { Debug.Log("http-post-async-request ===== " + url + " ===== " + content); HttpContent httpContent = new StringContent(content); try { var response = await _httpClient.PostAsync(url, httpContent); var responseContent = await response.Content.ReadAsStringAsync(); Debug.Log("http-post-async-result ===== " + url + "/resp ===== " + responseContent); return responseContent; } catch (Exception e) { Debug.Log("http-post-async-result ===== " + url + "/err ===== " + e); return null; } } public async Task GetAsync(string url) { Debug.Log("http-get-async-request ===== " + url + " ===== "); try { var response = await _httpClient.GetAsync(url); var responseContent = await response.Content.ReadAsStringAsync(); Debug.Log("http-get-async-result ===== " + url + "/resp ===== " + responseContent); return responseContent; } catch (Exception e) { Debug.Log("http-get-async-result ===== " + url + "/err ===== " + e); return null; } } } }