예제 #1
0
        public static async Task <string> GetTextAsync(string url, string authHeader)
        {
            UnityWebRequest webRequest = new UnityWebRequest(url, "GET");

            webRequest.downloadHandler = new DownloadHandlerBuffer();
            webRequest.SetRequestHeader("X-Api-Key", authHeader);

            await webRequest.SendWebRequestAsync();

            if (webRequest.IsSuccessStatusCode())
            {
                var content = webRequest.downloadHandler.text;
                return(content);
            }

            throw new Exception("Request failed");
        }
예제 #2
0
        public static async Task <byte[]> GetContentAsync(string url, string authHeader)
        {
            UnityWebRequest webRequest = new UnityWebRequest(url, "GET");

            webRequest.downloadHandler = new DownloadHandlerBuffer();
            webRequest.SetRequestHeader("X-Api-Key", authHeader);
            webRequest.SetRequestHeader("Accept", "");
            webRequest.SetRequestHeader("Content-Type", "application/octet-stream");

            await webRequest.SendWebRequestAsync();

            if (webRequest.IsSuccessStatusCode())
            {
                var content = webRequest.downloadHandler.data;
                return(content);
            }

            throw new Exception("Request failed");
        }