using System;
|
using Cysharp.Threading.Tasks;
|
using UnityEngine;
|
using UnityEngine.Networking;
|
|
|
public class HttpRequestEx
|
{
|
|
|
//回合战报
|
public static void UnityWebRequestTurnFightGet(string _url, string guid, int timeout = 5, Action<bool, string, byte[]> _result = null)
|
{
|
GetTurnFightData(_url, guid, timeout, _result).Forget();
|
}
|
|
static async UniTask GetTurnFightData(string remoteURL, string guid, int timeout, Action<bool, string, byte[]> _result = null)
|
{
|
|
UnityWebRequest request = UnityWebRequest.Get(remoteURL);
|
request.timeout = timeout;
|
|
try
|
{
|
await request.SendWebRequest();
|
if (request.isDone)
|
{
|
if (request.result == UnityWebRequest.Result.Success)
|
{
|
_result(true, guid, request.downloadHandler.data);
|
}
|
else
|
{
|
Debug.LogError("GetDataBEx 失败 " + request.result.ToString());
|
_result(false, guid, null);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
_result(false, guid, null);
|
Debug.LogError($"GetDataBEx 异常 - URL: {remoteURL}, Exception: {ex.Message}");
|
}
|
finally
|
{
|
request.Dispose();
|
}
|
}
|
|
|
}
|