Example #1
0
    /**<summary> Delete Item from server </summary>*/
    public static async Task <bool> DeleteItem(string gameID, string itemID)
    {
        UnityWebRequest www = UnityWebRequest.Delete(App.config.apiURL + "/games/" + gameID + "/items/" + itemID);

        www.downloadHandler = new DownloadHandlerBuffer();
        www.SendWebRequest();

        while (!www.isDone)
        {
            await Task.Delay(100);
        }

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
            Debug.Log(www.downloadHandler.text);
            OnDeleteItemResponse?.Invoke(false);
            return(false);
        }
        else
        {
            Debug.Log(www.downloadHandler.text);
            OnDeleteItemResponse?.Invoke(true);
            return(true);
        }
    }
Example #2
0
        /// <summary>Creates a Unity Web Request from the given parameters.</summary>
        /// <param name="uri">The Request URI (URL).</param>
        /// <param name="httpRequestMethod">The HTTP Request method to use.</param>
        /// <param name="data">The Custom Data that was sent along the Request.</param>
        /// <param name="timeout">The Request timeout in seconds).</param>
        /// <returns>The created unity web request.</returns>
        public static UnityWebRequest CreateWebRequest(string uri, HttpRequestMethod httpRequestMethod = HttpRequestMethod.Get, string data = null, int timeout = 2000)
        {
            UnityWebRequest unityWebRequest;

            switch (httpRequestMethod)
            {
            case HttpRequestMethod.Post:
                unityWebRequest = UnityWebRequest.Post(uri, data);
                break;

            case HttpRequestMethod.Put:
                unityWebRequest = UnityWebRequest.Put(uri, data);
                break;

            case HttpRequestMethod.Delete:
                unityWebRequest = UnityWebRequest.Delete($"{uri}?{data}");
                break;

            case HttpRequestMethod.Head:
                unityWebRequest = UnityWebRequest.Head($"{uri}?{data}");
                break;

            default:
                unityWebRequest = UnityWebRequest.Get($"{uri}?{data}");
                break;
            }
            unityWebRequest.timeout = timeout;
            return(unityWebRequest);
        }
Example #3
0
        public static UnityWebRequest Delete(string url)
        {
            var www = UnityWebRequest.Delete(ApiUrl + url);

            www = SetAuth(www);
            return(www);
        }
Example #4
0
 /// <summary>
 /// Rest DELETE.
 /// </summary>
 /// <param name="query">Finalized Endpoint Query with parameters.</param>
 /// <param name="headers">Optional header information for the request.</param>
 /// <param name="timeout">Optional time in seconds before request expires.</param>
 /// <param name="readResponseData">Optional bool. If its true, response data will be read from web request download handler.</param>
 /// <param name="certificateHandler">Optional certificate handler for custom certificate verification</param>
 /// <param name="disposeCertificateHandlerOnDispose">Optional bool. If true and <paramref name="certificateHandler"/> is not null, <paramref name="certificateHandler"/> will be disposed, when the underlying UnityWebRequest is disposed.</param>
 /// <returns>The response data.</returns>
 public static async Task <Response> DeleteAsync(string query, Dictionary <string, string> headers = null, int timeout = -1, bool readResponseData = false, CertificateHandler certificateHandler = null, bool disposeCertificateHandlerOnDispose = true)
 {
     using (var webRequest = UnityWebRequest.Delete(query))
     {
         return(await ProcessRequestAsync(webRequest, timeout, headers, readResponseData, certificateHandler, disposeCertificateHandlerOnDispose));
     }
 }
Example #5
0
    public IEnumerator DeleteAudioClip(string fileName)
    {
        Debug.Log("Deleting an audio clip: " + fileName);
        UnityWebRequest www = UnityWebRequest.Delete("http://" + m_serverIP + ":" + m_serverPort + "?fn=" + fileName);

        www.downloadHandler = new DownloadHandlerBuffer();
        yield return(www.Send());

        if (www.isNetworkError)
        {
            Debug.Log(www.error);
        }
        else
        {
            string result = DownloadHandlerBuffer.GetContent(www);
            if (result == null)
            {
                Debug.Log("Deletion confirmation is null");
            }
            else
            {
                Debug.Log(result.ToString());
            }
        }
    }
    IEnumerator deleteRequest(string route, Action <string> call = null)
    {
        string authorization = authenticate(scrData.access("email"), scrData.access("pwd"));

        using (UnityWebRequest www = UnityWebRequest.Delete(scrData.access("api_address") + route))
        {
            www.SetRequestHeader("AUTHORIZATION", authorization);
            print("delete/" + route);
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                instantiateErrorPopup();
                print(www.error);
            }
            else
            {
                //  print(www.downloadHandler.text);
                if (call != null)
                {
                    call("");
                }
            }
        }
    }
Example #7
0
    IEnumerator TerminatePresence()
    {
        // Se construye una petición HTTP DELETE con el ID del Servidor que hemos obtenido.
        UnityWebRequest del = UnityWebRequest.Delete(GlobalVars.BASE_WEBURL + GlobalVars.serverId);

        // Realizamos la petición.
        yield return(del.SendWebRequest());

        // Si hay errores, se imprimen.
        if (del.isHttpError || del.isNetworkError)
        {
            Debug.LogError(del.error);
            Debug.LogError(del.downloadHandler.text);
        }
        // Si no, se imprime el código de resultado.
        else
        {
            print(del.responseCode);
            if (Application.isBatchMode)
            {
                Console.WriteLine("ServerID " + GlobalVars.serverId + " is no longer available to the public!");
            }
            GlobalVars.serverId = 0;
        }
    }
        public IEnumerator DeleteAnchorSet(AnchorSet anchorSet)
        {
            using (var request = UnityWebRequest.Delete(string.Format("{0}/{1}", Globals.ServiceBaseUrl + AnchorSetsUrl, anchorSet.id)))
            {
                request.AddApiKeyHeader(Globals.ApiKey);

                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    Debug.Log(request.error);
                    yield break;
                }

                for (int i = 0; i < ContentArea.transform.childCount; i++)
                {
                    var child   = ContentArea.transform.GetChild(i);
                    var binding = child.GetComponent <AnchorSetBinding>();

                    if (binding.Context == anchorSet)
                    {
                        Destroy(child.gameObject);
                        break;
                    }

                    yield return(new WaitForEndOfFrame());
                }

                SelectedAnchorSet = null;
            }
        }
Example #9
0
        /// <summary>
        /// Make a HTTP DELETE request.
        /// </summary>
        /// <param name="url">A URL to post data.</param>
        /// <param name="token">An access token.</param>
        /// <param name="onSuccess">Callback, called when status is in the 200 range.</param>
        /// <param name="onError">Callback, called when the request has an error.</param>
        /// <returns>An IEnumerator.</returns>
        static public IEnumerator delete(string url,
                                         string token,
                                         Action onSuccess,
                                         Action <string> onError)
        {
            using (UnityWebRequest request = UnityWebRequest.Delete(url))
            {
                request.method = UnityWebRequest.kHttpVerbDELETE;
                request.SetRequestHeader("Accept", "application/text");
                request.SetRequestHeader("Cookie", "ExperienceCapture-Access-Token=" + token);
                request.timeout = 3; // 3 seconds

                yield return(request.SendWebRequest());

                if (request.isNetworkError || request.isHttpError)
                {
                    Debug.Log("Error Code: " + request.responseCode);
                    onError(request.error);
                }
                else
                {
                    onSuccess();
                }
            }
        }
Example #10
0
    public static UnityWebRequestAsyncOperation Delete(DatabaseCollections collection, string objectId)
    {
        UnityWebRequest www = UnityWebRequest.Delete(databaseURI + collection.ToString() + "/" + objectId);

        addHeaders(www);
        return(www.SendWebRequest());
    }
Example #11
0
    public static bool DeleteRequest(string url)
    {
        using (UnityWebRequest request = UnityWebRequest.Delete(host + url))
        {
            request.SendWebRequest();
            while (!request.isDone)
            {
                Thread.Sleep(50);
            }

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.Log($"{request.error}: {request.downloadHandler.text}");
            }
            else
            if (request.responseCode == 200)
            {
                return(true);
            }
            else
            {
                return(false);
            }

            return(false);
        }
    }
Example #12
0
    public IEnumerator SendRemovePhotoRequest(string url)
    {
        var x = UnityWebRequest.Delete(url);

        x.certificateHandler = new BypassCertificate();
        yield return(x.SendWebRequest());
    }
Example #13
0
    public UnityWebRequest DELETE(string url, WebCallback callback)
    {
        UnityWebRequest www = UnityWebRequest.Delete(url);

        WaitForRequest(www, callback);
        return(www);
    }
Example #14
0
    protected IEnumerator DELETE(Action <string> callback = null)
    {
        using (UnityWebRequest www = UnityWebRequest.Delete(path))
        {
            SetHandlers(www);
            SetRequestHeaders(www);
            yield return(www.Send());

            CheckResponseHeaders(www);

            if (www.isError)
            {
                if (callback != null)
                {
                    Debug.Log(www.error);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(www.downloadHandler.text);
                }
            }
        }
    }
        public IHttpRequest Delete(string uri)
        {
            var request = UnityWebRequest.Delete(uri);

            request.downloadHandler = new DownloadHandlerBuffer();
            return(new UnityHttpRequest(request));
        }
        private IEnumerator DeleteOperatorCommentCoroutine(IObserver <Unit> observer)
        {
            var url = string.Format("http://live2.nicovideo.jp/watch/{0}/operator_comment", NicoliveProgramId);

            using (var www = UnityWebRequest.Delete(url))
            {
                www.SetRequestHeader("Cookie", "user_session=" + _niconicoUser.UserSession);
                www.SetRequestHeader("User-Agent", _userAgent);

#if UNITY_2017_2_OR_NEWER
                yield return(www.SendWebRequest());
#else
                yield return(www.Send());
#endif

#if UNITY_2017_1_OR_NEWER
                if (www.isHttpError || www.isNetworkError)
#else
                if (www.isError)
#endif
                {
                    observer.OnError(new NicoliveApiClientException(www.downloadHandler.text));
                    yield break;
                }

                observer.OnNext(Unit.Default);
                observer.OnCompleted();
            }
        }
Example #17
0
        public static async Task <T> DeleteAsync <T>(string uri)
        {
            UnityWebRequest request = UnityWebRequest.Delete(uri);
            await request.SendWebRequest();

            return(JsonUtility.FromJson <T>(request.downloadHandler.text));
        }
Example #18
0
        private IEnumerator StartDelete(HttpRequest request)
        {
            var url = request.Url + "?";
            //反射用来填充Url
            Type type = Type.GetType(request.MsgName);
            var  Msg  = Convert.ChangeType(request.Msg, type);

            PropertyInfo[] properties = Msg.GetType().GetProperties();
            for (int i = 0; i < properties.Length; i++)
            {
                url += $"{properties[i].Name}={properties[i].GetValue(Msg)}";
                if (i != properties.Length - 1)
                {
                    url += "&";
                }
            }
            request.Url = url;
            using (UnityWebRequest www = UnityWebRequest.Delete(request.Url))
            {
                www.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey();
                www.downloadHandler    = new DownloadHandlerBuffer();
                www.SetRequestHeader("Content-Type", "application/json");
                www.SetRequestHeader("token", token);
                yield return(www.SendWebRequest());

                DealResult(www, request);
            }
        }
Example #19
0
    public static UnityWebRequest Delete(string url, string id)
    {
        var task = UnityWebRequest.Delete(url);

        ApplyHeaders(task);
        return(task);
    }
        private static UnityWebRequest BuildRequest(string method, Uri uri, IDictionary <string, string> headers,
                                                    byte[] body, int timeout)
        {
            UnityWebRequest www;

            if (string.Equals(method, "POST", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(method, "PUT", StringComparison.OrdinalIgnoreCase))
            {
                www = new UnityWebRequest(uri, method)
                {
                    uploadHandler   = new UploadHandlerRaw(body),
                    downloadHandler = new DownloadHandlerBuffer()
                };
            }
            else if (string.Equals(method, "DELETE", StringComparison.OrdinalIgnoreCase))
            {
                www = UnityWebRequest.Delete(uri);
            }
            else
            {
                www = UnityWebRequest.Get(uri);
            }

            www.SetRequestHeader("Content-Type", "application/json");
            foreach (var kv in headers)
            {
                www.SetRequestHeader(kv.Key, kv.Value);
            }

            www.timeout = timeout;
            return(www);
        }
Example #21
0
        private IEnumerator <float> DeleteEnumerator(string url, Action successHandler, Action <string, string> exceptionHandler)
        {
            UnityWebRequest request = UnityWebRequest.Delete(url);

            Debug.Log(url);

            if (headers != null && headers.Count > 0)
            {
                foreach (var header in headers)
                {
                    Debug.Log(header.Key + " " + header.Value);
                    request.SetRequestHeader(header.Key, header.Value);
                }
            }

            request.SendWebRequest();

            while (!request.isDone)
            {
                yield return(0);
            }

            if (request.isHttpError || request.isNetworkError)
            {
                exceptionHandler?.Invoke(request.error, "");
                Debug.LogError(request.error);
            }
            else
            {
                successHandler?.Invoke();
            }
        }
Example #22
0
 /// <summary>
 /// Rest DELETE.
 /// </summary>
 /// <param name="query">Finalized Endpoint Query with parameters.</param>
 /// <param name="headers">Optional header information for the request.</param>
 /// <param name="timeout">Optional time in seconds before request expires.</param>
 /// <param name="readResponseData">Optional bool. If its true, response data will be read from web request download handler.</param>
 /// <returns>The response data.</returns>
 public static async Task <Response> DeleteAsync(string query, Dictionary <string, string> headers = null, int timeout = -1, bool readResponseData = false)
 {
     using (var webRequest = UnityWebRequest.Delete(query))
     {
         return(await ProcessRequestAsync(webRequest, timeout, headers, readResponseData));
     }
 }
    /// <summary>
    /// Send request delete to remove user from leaderboard
    /// </summary>
    private IEnumerator SubmitRemoveUser(string userId)
    {
        UnityWebRequest www = UnityWebRequest.Delete(_Url + _Port + "/users/" + userId);

        float startTime = Time.time;

        ui.loadingView.SetActive(true);
        yield return(www.Send());

        ui.loadingView.SetActive(false);

        if (www.isNetworkError)
        {
            // There was an error
            Debug.Log(www.error);
        }
        else
        {
            if (www.responseCode == 200)
            {
                getSpentTimesForRequest(startTime, "Delete User");
                // Response code 200 signifies that the server had no issues with the data we went
                CallGetUsersForAdmin();
            }
            else
            {
                // Any other response signifies that there was an issue with the data we sent
                Debug.Log("Error response code:" + www.responseCode.ToString());
            }
        }
    }
        /// <summary> Send a web request now. Call the callback with the response processed by the resultProcessor. </summary>
        public static void SendRequest(Task task)
        {
            UnityWebRequest request;

            switch (task.type)              //https://forum.unity.com/threads/posting-raw-json-into-unitywebrequest.397871/
            {
            default:
            case Task.Type.Get:
                request = UnityWebRequest.Get(task.uri);
                break;

            case Task.Type.Post:
                request        = UnityWebRequest.Put(task.uri, task.data);
                request.method = "POST";
                break;

            case Task.Type.Delete:
                request = UnityWebRequest.Delete(task.uri);
                break;

            case Task.Type.Patch:
                request        = UnityWebRequest.Put(task.uri, task.data);
                request.method = "PATCH";
                break;
            }

            request.SetRequestHeader("Authorization", string.Format("Token token=\"{0}\"", Settings.token));
            request.SetRequestHeader("content-type", "application/json; charset=UTF-8");
            request.SendWebRequest().completed += (asyncOp) => { CompleteAsyncOperation(asyncOp, request, task); };
        }
Example #25
0
    public IEnumerator DeleteCoroutine(string url,
                                       float timeOut,
                                       Action <string> onFinish           = null,
                                       Action <float> onUploadDownloading = null)
    {
#if UNITY_EDITOR
        if (Tracking)
        {
            PrintTrack(MethodBase.GetCurrentMethod().Name);
            PrintTrack("url: " + url);
        }
#endif

#if VIRTUAL_SERVER
        if (VirtualServer.Instance.IsContainUrl(url))
        {
            if (onFinish != null)
            {
                onFinish(VirtualServer.Instance.Send(url));
            }
            yield break;
        }
#endif

        UnityWebRequest www = UnityWebRequest.Delete(url);
        yield return(WebRequestCoroutineCore(www, timeOut, onFinish, onUploadDownloading));
    }
Example #26
0
        public ApiRequest(string path, Method method, Dictionary <string, string> queryParams, string postBody, bool isAbsolutePath = false)
        {
            var url = (isAbsolutePath ? "" : ApiClient.Instance.BasePath) + path;

            if (queryParams != null && queryParams.Count > 0)
            {
                url += "?";
                foreach (var param in queryParams)
                {
                    url += param.Key + "=" + param.Value + "&";
                }
            }


            url = url.TrimEnd(new char[] { '&' });

            switch (method)
            {
            case Method.POST:
                www = UnityWebRequest.Post(url, postBody);
                break;

            case Method.DELETE:
                www = UnityWebRequest.Delete(url);
                break;

            default:
                www = UnityWebRequest.Get(url);
                break;
            }

            www.SetRequestHeader("Authorization", "Bearer " + ApiClient.Instance.AccessToken);
        }
Example #27
0
    private IEnumerator DeleteProfileRequest(string token)
    {
        UnityWebRequest requestDeleteProfile = UnityWebRequest.Delete("https://unitrivia.herokuapp.com/api/profile");

        requestDeleteProfile.SetRequestHeader("jwt", token);
        yield return(requestDeleteProfile.SendWebRequest());

        //Debug.Log("ResponseCode: " + requestDeleteProfile.responseCode);

        if (requestDeleteProfile.result == UnityWebRequest.Result.ConnectionError)
        {
            //Debug.Log("ERROR CONNECTION:" + requestDeleteProfile.result);

            ErrorDataScript.setErrorText("Error de conexión");
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else if (requestDeleteProfile.responseCode != 200)
        {
            //Debug.Log("ERROR DELETE:" + requestDeleteProfile.downloadHandler.text);
            ServerReturn result = ServerReturn.CreateFromJSON(requestDeleteProfile.downloadHandler.text);

            ErrorDataScript.setErrorText(result.message);
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else
        {
            //Debug.Log("EXITO DELETE:" + requestDeleteProfile.downloadHandler.text);

            SuccessDataScript.setSuccessText("Usuario eliminado correctamente!");
            SuccessDataScript.setReturnScene("Login Scene");
            SceneManager.LoadScene("Success Scene", LoadSceneMode.Additive);
        }
    }
 /// <summary>
 /// Rest DELETE.
 /// </summary>
 /// <param name="query">Finalized Endpoint Query with parameters.</param>
 /// <param name="headers">Optional header information for the request.</param>
 /// <returns>The response data.</returns>
 public static async Task <Response> DeleteAsync(string query, Dictionary <string, string> headers = null)
 {
     using (var webRequest = UnityWebRequest.Delete(query))
     {
         return(await ProcessRequestAsync(webRequest, headers));
     }
 }
Example #29
0
    private IEnumerator HandleDeleteWaypoints(string hostUrl)
    {
        UnityWebRequest request = UnityWebRequest.Delete(hostUrl + "/map");

        request.SetRequestHeader("Accept", "application/json");

        yield return(request.SendWebRequest());
    }
Example #30
0
    public static UnityWebRequest DeleteRequest(string url)
    {
        var request = UnityWebRequest.Delete(url);

        request = AddCommonHeaders(request);
        request.SendWebRequest();
        return(request);
    }