Unity 异步Post 请求方式
作者:互联网
private async Task<bool> SendTrainingResult(PracticeRecords practiceRecords)
{
bool isSendSucceed = true;
JsonData jsonData = new JsonData();
jsonData["UserID"] = practiceRecords.UserID;
jsonData["ModelID"] = practiceRecords.ModelID;
jsonData["StartTime"] = practiceRecords.StartTime;
jsonData["StopTime"] = practiceRecords.StopTime;
string data = jsonData.ToJson();
try
{
using (HttpClient httpClient = new HttpClient())
{
HttpContent httpContent = new StringContent(data);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(LoadFileManager.Instance.GetHttpInterfaceUrl("练习记录"), httpContent);
httpResponseMessage.EnsureSuccessStatusCode();
string str = await httpResponseMessage.Content.ReadAsStringAsync();
Debug.Log(str);
}
}
catch (Exception e)
{
isSendSucceed = false;
Debug.LogError(e);
}
return isSendSucceed;
}
协议和返回值换成自己想要的!
标签:异步,isSendSucceed,practiceRecords,httpResponseMessage,jsonData,Unity,new,Post,htt 来源: https://blog.csdn.net/L877790502/article/details/113588822