コード例 #1
0
 private void InitRequest(UnityWebRequest webRequest, HttpParams args)
 {
     if (args.timeout > 0)
     {
         webRequest.timeout = args.timeout;
     }
 }
コード例 #2
0
        IEnumerator OnDeleteCoroutine(int id, HttpParams args)
        {
            var newUrl  = args.url;
            var request = UnityWebRequest.Delete(newUrl);

            InitRequest(request, args);

            yield return(request.SendWebRequest());

            OnRequestCallback(id, request, args);
        }
コード例 #3
0
        IEnumerator OnPutCoroutine(int id, HttpParams args)
        {
            var newUrl  = args.url;
            var request = UnityWebRequest.Put(newUrl, args.bodyData);

            InitRequest(request, args);

            yield return(request.SendWebRequest());

            OnRequestCallback(id, request, args);
        }
コード例 #4
0
        IEnumerator OnGetCoroutine(int id, HttpParams args)
        {
            var newUrl  = (args.formData != null) ? args.formData.ToGetData(args.url): args.url;
            var request = UnityWebRequest.Get(newUrl);

            InitRequest(request, args);

            yield return(request.SendWebRequest());

            OnRequestCallback(id, request, args);
        }
コード例 #5
0
        IEnumerator OnPostCoroutine(int id, HttpParams args)
        {
            var wwwForm = (args.formData != null) ? args.formData.ToPostData(args.url) : null;
            var request = UnityWebRequest.Post(args.url, wwwForm);

            InitRequest(request, args);

            yield return(request.SendWebRequest());

            OnRequestCallback(id, request, args);
        }
コード例 #6
0
        void OnRequestCallback(int id, UnityWebRequest webRequest, HttpParams args)
        {
            var result = new HttpResult(webRequest);

            if (webRequest.isHttpError || webRequest.isNetworkError || !webRequest.isDone)
            {
                args.onFailed?.Invoke(webRequest.error);
            }
            else
            {
                args.onSuccess?.Invoke(webRequest.downloadHandler.data);
            }
            args.onCallback?.Invoke(result);
            m_coroutines.Remove(id);
        }
コード例 #7
0
        private int StartRequest(RequestMode requestMode, HttpParams args)
        {
            if (args == null)
            {
                return(-1);
            }

            if (string.IsNullOrEmpty(args.url))
            {
                return(-1);
            }

            var       newId     = m_coroutineId++;
            Coroutine coroutine = null;

            switch (requestMode)
            {
            case RequestMode.Post:
                coroutine = StartCoroutine(OnPostCoroutine(newId, args));
                break;

            case RequestMode.Get:
                coroutine = StartCoroutine(OnGetCoroutine(newId, args));
                break;

            case RequestMode.Put:
                coroutine = StartCoroutine(OnPutCoroutine(newId, args));
                break;

            case RequestMode.Delete:
                coroutine = StartCoroutine(OnDeleteCoroutine(newId, args));
                break;
            }
            m_coroutines[newId] = coroutine;
            return(newId);
        }
コード例 #8
0
 public int Delete(HttpParams args)
 {
     return(StartRequest(RequestMode.Delete, args));
 }
コード例 #9
0
 public int Put(HttpParams args)
 {
     return(StartRequest(RequestMode.Put, args));
 }
コード例 #10
0
 public int Get(HttpParams args)
 {
     return(StartRequest(RequestMode.Get, args));
 }