Inheritance: IDisposable
コード例 #1
0
            public UnityRequest(UnityHttpClientV2 inst, string url, HttpRequest request, object previousUserData, int requestId)
                : base(inst, request)
            {
                self = inst;
                OriginalRequest = request;
                RequestId = requestId;
                PreviousUserData = previousUserData;

                Request = new UnityWebRequest(url);
                // Auto-choose HTTP method
                Request.method = request.Method ?? (request.Body != null ? "POST" : "GET");
                // TODO Missing functionality (currently unsupported by UnityWebRequest).
                //				req.SetRequestHeader("User-agent", request.UserAgent);
                //				req.keepAlive = true;
                foreach (var pair in request.Headers) {
                    Request.SetRequestHeader(pair.Key, pair.Value);
                }

                if (OriginalRequest.Body != null) {
                    UploadHandler uploader = new UploadHandlerRaw(OriginalRequest.Body);
                    if (ContentType != null) uploader.contentType = ContentType;
                    Request.uploadHandler = uploader;
                }
                Request.downloadHandler = new DownloadHandlerBuffer();
            }
コード例 #2
0
ファイル: RESTService.cs プロジェクト: thijsvm/Bachelorproef
 private static void InitFudables(UnityWebRequest request)
 {
     JSONNode fundablesJSON = JSON.Parse(request.downloadHandler.text);
     foreach (JSONNode fundableNode in fundablesJSON.AsArray)
     {
         string id = fundableNode["_id"].Value;
         string name = fundableNode["name"].Value;
         string path = fundableNode["path"].Value;
         double totalCost = fundableNode["totalCost"].AsDouble;
         Fundable fundable = new Fundable(id, path, totalCost, null, (name == "") ? null : name);
         fundables.Add(fundable);
     }
     requestPool.Remove(request);
 }
コード例 #3
0
ファイル: RESTService.cs プロジェクト: thijsvm/Bachelorproef
        private static void InitBackers(UnityWebRequest request)
        {
            JSONNode backersJSON = JSON.Parse(request.downloadHandler.text);
            foreach (JSONNode backerNode in backersJSON.AsArray)
            {
                string id = backerNode["_id"].Value;
                string firstName = backerNode["firstName"].Value;
                string lastName = backerNode["lastName"].Value;
                string mail = backerNode["mail"].Value;

                Backer backer = new Backer(id, firstName, lastName, mail);
                backers.Add(backer);
            }
            requestPool.Remove(request);
        }
コード例 #4
0
 /// <summary>
 /// 下载文件
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="fileMode">Append为断点续传,Create为新建文件</param>
 /// <param name="remoteFileSize">Append模式下必传,远端文件大小</param>
 /// <param name="remoteLastModified">Append模式下必传,远端文件最后修改日期</param>
 /// <returns></returns>
 public static IEnumerator DownloadFile(string fileName, OnDownloadFileFinished onDownloadFileFinidhed,
     FileMode fileMode = FileMode.Create, long remoteFileSize = 0, DateTime remoteLastModified = new DateTime())
 {
     string url = BaseDownloadingURL + fileName;
     string filePath = Path.Combine(AssetBundleUtility.LocalAssetBundlePath, fileName);
     using (UnityWebRequest request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET))
     {
         if (File.Exists(filePath) && fileMode == FileMode.Append)
         {
             FileInfo localFileInfo = new FileInfo(filePath);
             bool isOutdate = remoteLastModified > localFileInfo.LastWriteTime;
             if(localFileInfo.Length == remoteFileSize && !isOutdate)//已下载完成
             {
                 onDownloadFileFinidhed(fileName, null);
                 yield break;
             }
             if (localFileInfo.Length < remoteFileSize && !isOutdate)//继续下载
             {
                 request.downloadHandler = new DownloadHandlerFile(filePath, FileMode.Append);
                 request.SetRequestHeader("Range", string.Format("bytes={0}-", localFileInfo.Length));
             }
             else//重新下载
             {
                 request.downloadHandler = new DownloadHandlerFile(filePath);
             }
         }
         else
         {
             request.downloadHandler = new DownloadHandlerFile(filePath);
         }
         CurrentRequest = request;
         yield return request.Send();
         string error = request.isError ?
             string.Format("DownloadFile Failed - url: {0}, responseCode: {1}, error: {2}", url, request.responseCode, request.error)
             : null;
         onDownloadFileFinidhed(fileName, error);
     }
     CurrentRequest = null;
 }
コード例 #5
0
 /// <summary>
 ///   <para>Returns the downloaded Texture, or null.</para>
 /// </summary>
 /// <param name="www">A finished UnityWebRequest object with DownloadHandlerTexture attached.</param>
 /// <returns>
 ///   <para>The same as DownloadHandlerTexture.texture</para>
 /// </returns>
 public static Texture2D GetContent(UnityWebRequest www)
 {
   return DownloadHandler.GetCheckedDownloader<DownloadHandlerTexture>(www).texture;
 }
コード例 #6
0
ファイル: RESTService.cs プロジェクト: thijsvm/Bachelorproef
        static IEnumerator UploadDonation(UnityWebRequest webRequest, Action onDataReceived)
        {
            if(webRequest == null) yield break;
            yield return webRequest.Send();

            if(webRequest.isError)
            {
                Debug.Log(webRequest.error);
            }
            else
            {
                Debug.Log("Upload donation, WebRequest " + webRequest.url + " done!");
                if(onDataReceived != null) onDataReceived();
            }
        }
コード例 #7
0
            private IEnumerator ProcessRequest(UnityWebRequest req)
            {
                yield return req.Send();

                if (req.isError) {
                    if (!WasAborted) {
                        string errorMessage = "Failed web request: " + req.error;
                        Common.Log(errorMessage);
                        self.FinishWithRequest(this, new HttpResponse(new Exception(errorMessage)));
                    }
                }
                else {
                    // Extracts asset bundle
                    HttpResponse response = new HttpResponse();
                    response.Body = Request.downloadHandler.data;
                    response.StatusCode = (int)Request.responseCode;
                    foreach (var pair in Request.GetResponseHeaders()) {
                        response.Headers[pair.Key] = pair.Value;
                    }
                    LogResponse(response);
                    self.FinishWithRequest(this, response);
                }
            }
コード例 #8
0
 public static UnityWebRequest Post(string uri, List<IMultipartFormSection> multipartFormSections, byte[] boundary)
 {
     UnityWebRequest request = new UnityWebRequest(uri, "POST");
     UploadHandler handler = new UploadHandlerRaw(SerializeFormSections(multipartFormSections, boundary)) {
         contentType = "multipart/form-data; boundary=" + Encoding.UTF8.GetString(boundary, 0, boundary.Length)
     };
     request.uploadHandler = handler;
     request.downloadHandler = new DownloadHandlerBuffer();
     return request;
 }
コード例 #9
0
 public static UnityWebRequest Post(string uri, string postData)
 {
     UnityWebRequest request = new UnityWebRequest(uri, "POST");
     string s = WWWTranscoder.URLEncode(postData, Encoding.UTF8);
     request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(s));
     request.uploadHandler.contentType = "application/x-www-form-urlencoded";
     request.downloadHandler = new DownloadHandlerBuffer();
     return request;
 }
コード例 #10
0
ファイル: Loader.cs プロジェクト: hrajagop/2DShooter
    IEnumerator LoadManifestFromWebRequest()
    {
        var url = GetManifestURL();
        var www = new UnityWebRequest(url) { downloadHandler = new DownloadHandlerAssetBundle(url, 0) };
        yield return www.Send();

        var assetBundle = ((DownloadHandlerAssetBundle)(www.downloadHandler)).assetBundle;
        var assets = assetBundle.LoadAllAssets();

        AddLoadedBundleToManager(assetBundle, assets[0].name);

        manifest = (AssetBundleManifest)assets[0];
    }
コード例 #11
0
 private static string GetErrorDescription(UnityWebRequest.UnityWebRequestError errorCode)
 {
   switch (errorCode)
   {
     case UnityWebRequest.UnityWebRequestError.OK:
       return "No Error";
     case UnityWebRequest.UnityWebRequestError.SDKError:
       return "Internal Error With Transport Layer";
     case UnityWebRequest.UnityWebRequestError.UnsupportedProtocol:
       return "Specified Transport Protocol is Unsupported";
     case UnityWebRequest.UnityWebRequestError.MalformattedUrl:
       return "URL is Malformatted";
     case UnityWebRequest.UnityWebRequestError.CannotResolveProxy:
       return "Unable to resolve specified proxy server";
     case UnityWebRequest.UnityWebRequestError.CannotResolveHost:
       return "Unable to resolve host specified in URL";
     case UnityWebRequest.UnityWebRequestError.CannotConnectToHost:
       return "Unable to connect to host specified in URL";
     case UnityWebRequest.UnityWebRequestError.AccessDenied:
       return "Remote server denied access to the specified URL";
     case UnityWebRequest.UnityWebRequestError.GenericHTTPError:
       return "Unknown/Generic HTTP Error - Check HTTP Error code";
     case UnityWebRequest.UnityWebRequestError.WriteError:
       return "Error when transmitting request to remote server - transmission terminated prematurely";
     case UnityWebRequest.UnityWebRequestError.ReadError:
       return "Error when reading response from remote server - transmission terminated prematurely";
     case UnityWebRequest.UnityWebRequestError.OutOfMemory:
       return "Out of Memory";
     case UnityWebRequest.UnityWebRequestError.Timeout:
       return "Timeout occurred while waiting for response from remote server";
     case UnityWebRequest.UnityWebRequestError.HTTPPostError:
       return "Error while transmitting HTTP POST body data";
     case UnityWebRequest.UnityWebRequestError.SSLCannotConnect:
       return "Unable to connect to SSL server at remote host";
     case UnityWebRequest.UnityWebRequestError.Aborted:
       return "Request was manually aborted by local code";
     case UnityWebRequest.UnityWebRequestError.TooManyRedirects:
       return "Redirect limit exceeded";
     case UnityWebRequest.UnityWebRequestError.ReceivedNoData:
       return "Received an empty response from remote host";
     case UnityWebRequest.UnityWebRequestError.SSLNotSupported:
       return "SSL connections are not supported on the local machine";
     case UnityWebRequest.UnityWebRequestError.FailedToSendData:
       return "Failed to transmit body data";
     case UnityWebRequest.UnityWebRequestError.FailedToReceiveData:
       return "Failed to receive response body data";
     case UnityWebRequest.UnityWebRequestError.SSLCertificateError:
       return "Failure to authenticate SSL certificate of remote host";
     case UnityWebRequest.UnityWebRequestError.SSLCipherNotAvailable:
       return "SSL cipher received from remote host is not supported on the local machine";
     case UnityWebRequest.UnityWebRequestError.SSLCACertError:
       return "Failure to authenticate Certificate Authority of the SSL certificate received from the remote host";
     case UnityWebRequest.UnityWebRequestError.UnrecognizedContentEncoding:
       return "Remote host returned data with an unrecognized/unparseable content encoding";
     case UnityWebRequest.UnityWebRequestError.LoginFailed:
       return "HTTP authentication failed";
     case UnityWebRequest.UnityWebRequestError.SSLShutdownFailed:
       return "Failure while shutting down SSL connection";
     default:
       return "Unknown error";
   }
 }
コード例 #12
0
 internal void InternalSetMethod(UnityWebRequest.UnityWebRequestMethod methodType);
コード例 #13
0
 public static UnityWebRequest Post(string uri, Dictionary<string, string> formFields)
 {
   UnityWebRequest unityWebRequest = new UnityWebRequest(uri, "POST");
   UploadHandler uploadHandler = (UploadHandler) new UploadHandlerRaw(UnityWebRequest.SerializeSimpleForm(formFields));
   uploadHandler.contentType = "application/x-www-form-urlencoded";
   unityWebRequest.uploadHandler = uploadHandler;
   unityWebRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
   return unityWebRequest;
 }
コード例 #14
0
 /// <summary>
 ///   <para>Create a UnityWebRequest configured to send form data to a server via HTTP POST.</para>
 /// </summary>
 /// <param name="uri">The target URI to which form data will be transmitted.</param>
 /// <param name="formData">Form fields or files encapsulated in a WWWForm object, for formatting and transmission to the remote server.</param>
 /// <returns>
 ///   <para>A UnityWebRequest configured to send form data to uri via POST.</para>
 /// </returns>
 public static UnityWebRequest Post(string uri, WWWForm formData)
 {
   UnityWebRequest unityWebRequest = new UnityWebRequest(uri, "POST");
   unityWebRequest.uploadHandler = (UploadHandler) new UploadHandlerRaw(formData.data);
   unityWebRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
   using (Dictionary<string, string>.Enumerator enumerator = formData.headers.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       KeyValuePair<string, string> current = enumerator.Current;
       unityWebRequest.SetRequestHeader(current.Key, current.Value);
     }
   }
   return unityWebRequest;
 }
コード例 #15
0
 /// <summary>
 ///   <para>Returns the downloaded AssetBundle, or null.</para>
 /// </summary>
 /// <param name="www">A finished UnityWebRequest object with DownloadHandlerAssetBundle attached.</param>
 /// <returns>
 ///   <para>The same as DownloadHandlerAssetBundle.assetBundle</para>
 /// </returns>
 public static AssetBundle GetContent(UnityWebRequest www)
 {
     return(DownloadHandler.GetCheckedDownloader <DownloadHandlerAssetBundle>(www).assetBundle);
 }
コード例 #16
0
 /// <summary>
 ///   <para>Returns the downloaded AssetBundle, or null.</para>
 /// </summary>
 /// <param name="www">A finished UnityWebRequest object with DownloadHandlerAssetBundle attached.</param>
 /// <returns>
 ///   <para>The same as DownloadHandlerAssetBundle.assetBundle</para>
 /// </returns>
 public static AssetBundle GetContent(UnityWebRequest www)
 {
   return DownloadHandler.GetCheckedDownloader<DownloadHandlerAssetBundle>(www).assetBundle;
 }
コード例 #17
0
ファイル: RESTService.cs プロジェクト: thijsvm/Bachelorproef
        static IEnumerator PerformWebRequest(UnityWebRequest webRequest, Action<UnityWebRequest> onDataReceived = null)
        {
            if(webRequest == null) yield break;
            yield return webRequest.Send();

            if(webRequest.isError)
            {
                Debug.Log(webRequest.error);
            }
            else
            {
                Debug.Log("WebRequest " + webRequest.url + " done!");
                if(onDataReceived != null) onDataReceived(webRequest);
            }
        }
コード例 #18
0
 public static UnityWebRequest Post(string uri, WWWForm formData)
 {
     UnityWebRequest request = new UnityWebRequest(uri, "POST") {
         uploadHandler = new UploadHandlerRaw(formData.data),
         downloadHandler = new DownloadHandlerBuffer()
     };
     foreach (KeyValuePair<string, string> pair in formData.headers)
     {
         request.SetRequestHeader(pair.Key, pair.Value);
     }
     return request;
 }
コード例 #19
0
ファイル: RESTService.cs プロジェクト: thijsvm/Bachelorproef
 private static void UpdateBackersAndFundables(UnityWebRequest request)
 {
     JSONNode donationsJSON = JSON.Parse(request.downloadHandler.text);
     foreach (JSONNode donationNode in donationsJSON.AsArray)
     {
         double amount = donationNode["amount"].AsDouble;
         string fundableID = donationNode["fundable"].Value;
         string backerID = donationNode["backer"].Value;
         try
         {
             Fundable fundable = fundables.Find(f => f.Id == fundableID);
             Backer backer = backers.Find(b => b.Id == backerID);
             fundable.AddBacker(backer, amount);
             backer.AddNewBackedFundable(fundable, amount);
         }
         catch(ArgumentNullException e){
             Debug.Log(e);
         }
     }
     requestPool.Remove(request);
 }
コード例 #20
0
 public static UnityWebRequest Post(string uri, Dictionary<string, string> formFields)
 {
     UnityWebRequest request = new UnityWebRequest(uri, "POST");
     UploadHandler handler = new UploadHandlerRaw(SerializeSimpleForm(formFields)) {
         contentType = "application/x-www-form-urlencoded"
     };
     request.uploadHandler = handler;
     request.downloadHandler = new DownloadHandlerBuffer();
     return request;
 }
コード例 #21
0
 /// <summary>
 ///   <para>Returns a copy of the native-memory buffer interpreted as a UTF8 string.</para>
 /// </summary>
 /// <param name="www">A finished UnityWebRequest object with DownloadHandlerBuffer attached.</param>
 /// <returns>
 ///   <para>The same as DownloadHandlerBuffer.text</para>
 /// </returns>
 public static string GetContent(UnityWebRequest www)
 {
   return DownloadHandler.GetCheckedDownloader<DownloadHandlerBuffer>(www).text;
 }