コード例 #1
0
ファイル: Coach.cs プロジェクト: coach-ml/coach-ul-2018
        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
ファイル: Coach.cs プロジェクト: coach-ml/coach-ul-2018
        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");
        }