2025-09-01 06:57:00 +00:00
|
|
|
using System;
|
2025-09-23 11:34:24 +00:00
|
|
|
using System.Net;
|
|
|
|
using System.Text;
|
2025-09-01 06:57:00 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
public class SDKEditorNetworkTool
|
|
|
|
{
|
|
|
|
public static string GetText(string url)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
|
|
{
|
|
|
|
www.timeout = 10; // 设置超时时间为10秒
|
|
|
|
www.SendWebRequest(); // 同步发送请求
|
|
|
|
|
|
|
|
while (www.isDone == false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (www.result != UnityWebRequest.Result.Success)
|
|
|
|
{
|
|
|
|
Debug.LogError($"Request failed: {www.error}");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (www.responseCode != 200)
|
|
|
|
{
|
|
|
|
Debug.LogWarning($"Unexpected status code: {www.responseCode}");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return www.downloadHandler.text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2025-09-23 11:34:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
public static string HttpGetText(string url)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (WebClient client = new WebClient())
|
|
|
|
{
|
|
|
|
client.Encoding = Encoding.UTF8;
|
|
|
|
return client.DownloadString(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
UnityEngine.Debug.LogError($"[NetworkTool] Exception: {e}");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2025-09-01 06:57:00 +00:00
|
|
|
}
|