Пример #1
0
        IEnumerator PostText(string url, RequestContainer details)
        {
            //string url = string.Empty;
            //RequestContainer details = _requests[url];

            using (UnityWebRequest www = UnityWebRequest.Post(url, details.Form))
            {
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    //OnWebRequestFailed(new WebContextException(www.error));
                    details.OnFailed(new WebContextException(www.error));
                }
                else
                {
                    // Show results as text
                    //Debug.Log(www.downloadHandler.text);
                    string rawData = www.downloadHandler.text;

                    var webRequestFactory = new Factory <IWebRequest>();
                    var webRequest        = webRequestFactory.Create <
                        WebResult.Concretes.UnityWebRequest>(rawData, www.url);

                    Debug.Log(webRequest.RawData);
                    details.OnSuccess(webRequest);
                }
            }
        }
Пример #2
0
        IEnumerator GetImageText(string url, RequestContainer details)
        {
            //string url = string.Empty;
            using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(url))
            {
                yield return(www.SendWebRequest());

                //RequestContainer details = _requests[www.url];
                if (www.isNetworkError || www.isHttpError)
                {
                    //OnWebRequestFailed(new WebContextException(www.error));
                    details.OnFailed(new WebContextException(www.error));
                }
                else
                {
                    // Show results as text
                    string rawData           = www.downloadHandler.text;
                    var    webRequestFactory = new Factory <IWebRequest>();

                    Texture2D tex           = DownloadHandlerTexture.GetContent(www);
                    byte[]    bytes         = tex.GetRawTextureData();
                    string    base64Encoded = bytes.Encode();

                    var webRequest = webRequestFactory.Create <
                        WebResult.Concretes.UnityWebRequest>(base64Encoded, www.url);


                    details.OnSuccess(webRequest);
                }
            }
        }