45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using System;
|
|
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 "";
|
|
}
|
|
} |