ProjectDDD/Assets/_DDD/_Scripts/GameFramework/Localization/GoogleSheetWebClient.cs
2025-07-17 19:11:00 +09:00

48 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.Networking;
using System.Text;
using System.Threading.Tasks;
namespace DDD
{
public static class GoogleSheetWebClient
{
public static async Task<string> Get(string url)
{
var req = UnityWebRequest.Get(url);
var op = req.SendWebRequest();
while (!op.isDone)
await Task.Yield();
if (req.result != UnityWebRequest.Result.Success)
{
Debug.LogError("GET Failed: " + req.error);
return null;
}
return req.downloadHandler.text;
}
public static async Task<string> Post(string url, string json)
{
var req = new UnityWebRequest(url, "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(json);
req.uploadHandler = new UploadHandlerRaw(bodyRaw);
req.downloadHandler = new DownloadHandlerBuffer();
req.SetRequestHeader("Content-Type", "application/json");
var op = req.SendWebRequest();
while (!op.isDone)
await Task.Yield();
if (req.result != UnityWebRequest.Result.Success)
{
Debug.LogError("POST Failed: " + req.error);
return null;
}
return req.downloadHandler.text;
}
}
}