diff --git a/Assets/WorkSpace/LH/Web/WebManager.cs b/Assets/WorkSpace/LH/Web/WebManager.cs index 90650573..3c9d1f9c 100644 --- a/Assets/WorkSpace/LH/Web/WebManager.cs +++ b/Assets/WorkSpace/LH/Web/WebManager.cs @@ -76,195 +76,6 @@ namespace UVC.Networks _webConfigLoader.LoadFromJsonString(json); } - //Post동작을 실행하는 함수입니다 - public void Request_Post(object inputclass, string type, System.Action ResultCallback) - { - //입력된 클래스를 json데이터로 변환합니다. - string json = JsonConvert.SerializeObject(inputclass); - StartCoroutine(Web_Post(_webConfigLoader.BaseUrl + type, json, (result, text) => - { - ResultCallback(result, text); - })); - } - - //Get동작을 실행하는 함수입니다. - public void Request_Get(string type, System.Action ResultCallback) - { - StartCoroutine(Web_Get(_webConfigLoader.BaseUrl + type, (result, text) => - { - ResultCallback(result, text); - })); - } - - //Put동작을 실행하는 함수입니다. - public void Request_Put(string type, System.Action ResultCallback) - { - StartCoroutine(Web_Put(_webConfigLoader.BaseUrl + type, (result, text) => - { - ResultCallback(result, text); - })); - } - - public void Request_Put(object inputclass, string type, System.Action ResultCallback) - { - string json = JsonConvert.SerializeObject(inputclass); - StartCoroutine(Web_Put(_webConfigLoader.BaseUrl + type, json, (result, text) => - { - ResultCallback(result, text); - })); - } - - IEnumerator Web_Post(string URL, string json, System.Action callback) - { - using (UnityWebRequest request = UnityWebRequest.PostWwwForm(URL, json)) - { - byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json); - - request.uploadHandler.Dispose(); - request.uploadHandler = new UploadHandlerRaw(jsonToSend); - request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); - request.SetRequestHeader("Content-Type", "application/json"); - request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token); - - yield return request.SendWebRequest(); - Debug.Log(URL); - Debug.Log(json); - - //result가 에러로 왔다면 - if ((request.result == UnityWebRequest.Result.ConnectionError) || (request.result == UnityWebRequest.Result.ProtocolError)) - { - Debug.Log(request.error); - //callback을 false로 하고 텍스트를 리턴합니다. - callback(false, request.downloadHandler.text); - } - else - { - //result가 에러가 아니라면, callback을 true로 하고 텍스트를 리턴합니다. - Debug.Log(request.downloadHandler.text); - callback(true, request.downloadHandler.text); - } - } - } - - IEnumerator Web_Get(string URL, System.Action callback) - { - using (UnityWebRequest request = UnityWebRequest.Get(URL)) - { - request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); - request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token); - - - yield return request.SendWebRequest(); - - //result가 에러로 왔다면 - if ((request.result == UnityWebRequest.Result.ConnectionError) || (request.result == UnityWebRequest.Result.ProtocolError)) - { - Debug.Log(request.error); - //callback을 false로 하고 텍스트를 리턴합니다. - callback(false, request.downloadHandler.text); - } - else - { - //result가 에러가 아니라면, callback을 true로 하고 텍스트를 리턴합니다. - Debug.Log(request.downloadHandler.text); - callback(true, request.downloadHandler.text); - } - } - } - - IEnumerator Web_Put(string URL, System.Action callback) - { - byte[] data = { }; - using (UnityWebRequest request = UnityWebRequest.Put(URL, data)) - { - request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); - request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token); - - - yield return request.SendWebRequest(); - - //result가 에러로 왔다면 - if ((request.result == UnityWebRequest.Result.ConnectionError) || (request.result == UnityWebRequest.Result.ProtocolError)) - { - Debug.Log(request.error); - //callback을 false로 하고 텍스트를 리턴합니다. - callback(false, request.downloadHandler.text); - } - else - { - //result가 에러가 아니라면, callback을 true로 하고 텍스트를 리턴합니다. - Debug.Log(request.downloadHandler.text); - callback(true, request.downloadHandler.text); - } - } - } - - IEnumerator Web_Put(string URL, string json, System.Action callback) - { - byte[] data = { }; - using (UnityWebRequest request = UnityWebRequest.Put(URL, data)) - { - byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json); - - request.uploadHandler.Dispose(); - request.uploadHandler = new UploadHandlerRaw(jsonToSend); - request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer(); - request.SetRequestHeader("Content-Type", "application/json"); - request.SetRequestHeader("Authorization", "Bearer " + _webConfigLoader.Token); - - yield return request.SendWebRequest(); - - //result가 에러로 왔다면 - if ((request.result == UnityWebRequest.Result.ConnectionError) || (request.result == UnityWebRequest.Result.ProtocolError)) - { - Debug.Log(request.error); - //callback을 false로 하고 텍스트를 리턴합니다. - callback(false, request.downloadHandler.text); - } - else - { - //result가 에러가 아니라면, callback을 true로 하고 텍스트를 리턴합니다. - Debug.Log(request.downloadHandler.text); - callback(true, request.downloadHandler.text); - } - } - } - //별도의 Data Content 가 없을 경우 reqeustURL 과 callback 등 만을 parameter로 넘기면 됨 - //public void Reqeust_Get(string requestURL, Action callback, string json = "") - //{ - // RequestAsync(requestURL, RequestType.GET, json) - // .ContinueWith(result => callback?.Invoke(result)) - // .Forget(); - //} - - //public void Reqeust_Post(string requestURL, Action callback, string json = "") - //{ - // RequestAsync(requestURL, RequestType.POST, json) - // .ContinueWith(result => callback?.Invoke(result)) - // .Forget(); - //} - - //public void Reqeust_Put(string requestURL, Action callback, string json = "") - //{ - // RequestAsync(requestURL, RequestType.PUT, json) - // .ContinueWith(result => callback?.Invoke(result)) - // .Forget(); - //} - - //public void Reqeust_Patch(string requestURL, Action callback, string json = "") - //{ - // RequestAsync(requestURL, RequestType.PATCH, json) - // .ContinueWith(result => callback?.Invoke(result)) - // .Forget(); - //} - - //public void Reqeust_Delete(string requestURL, Action callback, string json = "") - //{ - // RequestAsync(requestURL, RequestType.DELETE, json) - // .ContinueWith(result => callback?.Invoke(result)) - // .Forget(); - //} - //별도의 Data Content 가 없을 경우 reqeustURL 과 callback 등 만을 parameter로 넘기면 됨 public void Reqeust(string requestURL, RequestType type , Action callback, object json = null) { @@ -285,9 +96,6 @@ namespace UVC.Networks } - - - private async UniTask RequestAsync(string requestURL, RequestType type, string json = "") { string fullUrl = _webConfigLoader.BaseUrl + requestURL; @@ -319,8 +127,6 @@ namespace UVC.Networks } } - - private bool IsSuccess(UnityWebRequest.Result result) { switch(result)