last update

This commit is contained in:
2023-07-09 23:43:19 +05:00
parent 47d8f95440
commit fe2ebf72c6
11 changed files with 2141 additions and 109 deletions
+27 -25
View File
@@ -37,7 +37,7 @@ public class NetworkService
catch { }
responseStruct.responseCode = getRequest.responseCode;
if(getRequest.responseCode != 200)
if (getRequest.responseCode != 200)
{
responseStruct.responseText = getRequest.downloadHandler.text;
return responseStruct;
@@ -50,7 +50,7 @@ public class NetworkService
return responseStruct;
}
catch(Exception ex)
catch (Exception ex)
{
responseStruct.responseCode = -1;
responseStruct.responseText = ex.Message;
@@ -86,7 +86,7 @@ public class NetworkService
catch { }
responseStruct.responseCode = getRequest.responseCode;
if(getRequest.responseCode != 200)
if (getRequest.responseCode != 200)
{
responseStruct.responseText = getRequest.downloadHandler.text;
return responseStruct;
@@ -98,7 +98,7 @@ public class NetworkService
responseStruct.responseData = result;
return responseStruct;
}
catch(Exception ex)
catch (Exception ex)
{
responseStruct.responseCode = -1;
responseStruct.responseText = ex.Message;
@@ -122,8 +122,8 @@ public class NetworkService
}
using var getRequest = UnityWebRequest.Get(_apiUrl + stringBuilder.ToString());
if(headers != null)
foreach(var header in headers)
if (headers != null)
foreach (var header in headers)
getRequest.SetRequestHeader(header.Key, header.Value);
getRequest.SetRequestHeader("Content-type", "application/json");
@@ -136,7 +136,7 @@ public class NetworkService
catch { }
responseStruct.responseCode = getRequest.responseCode;
if(getRequest.responseCode != 200)
if (getRequest.responseCode != 200)
{
responseStruct.responseText = getRequest.downloadHandler.text;
return responseStruct;
@@ -149,7 +149,7 @@ public class NetworkService
return responseStruct;
}
catch(Exception ex)
catch (Exception ex)
{
responseStruct.responseCode = -1;
responseStruct.responseText = ex.Message;
@@ -158,21 +158,22 @@ public class NetworkService
}
}
public async UniTask PostAsync<TValue> (string requestString, TValue data, Dictionary<string, string> headers = null)
{
public async UniTask PostAsync<TValue>(string requestString, TValue data, Dictionary<string, string> headers = null)
{
string sendingData = JsonConvert.SerializeObject(data);
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
postRequest.downloadHandler = new DownloadHandlerBuffer();
if(headers != null)
using var postRequest = new UnityWebRequest(_apiUrl + requestString, "POST");
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
postRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(dataBytes);
postRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
postRequest.SetRequestHeader("Content-Type", "application/json");
if (headers != null)
{
foreach(var header in headers)
foreach (var header in headers)
postRequest.SetRequestHeader(header.Key, header.Value);
}
postRequest.SetRequestHeader("Content-Type", "application/json");
UnityWebRequest operation = new UnityWebRequest();
try
@@ -182,17 +183,18 @@ public class NetworkService
catch { }
}
public async UniTask<Response<TResponseValue>> PostAsync<TSendingValue, TResponseValue> (string requestString, TSendingValue data)
public async UniTask<Response<TResponseValue>> PostAsync<TSendingValue, TResponseValue>(string requestString, TSendingValue data)
{
Response<TResponseValue> responseStruct = new Response<TResponseValue>();
string sendingData = JsonConvert.SerializeObject(data);
using var postRequest = UnityWebRequest.Post(_apiUrl + requestString, sendingData);
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
postRequest.uploadHandler = new UploadHandlerRaw(dataBytes);
postRequest.downloadHandler = new DownloadHandlerBuffer();
postRequest.SetRequestHeader("Content-Type", "application/json");
using var postRequest = new UnityWebRequest(_apiUrl + requestString, "POST");
byte[] dataBytes = new UTF8Encoding().GetBytes(sendingData);
postRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(dataBytes);
postRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
postRequest.SetRequestHeader("Content-Type", "application/json");
UnityWebRequest operation = new UnityWebRequest();
try
@@ -202,7 +204,7 @@ public class NetworkService
catch { }
responseStruct.responseCode = postRequest.responseCode;
if(postRequest.responseCode != 200)
if (postRequest.responseCode != 200)
{
responseStruct.responseText = postRequest.downloadHandler.text;
return responseStruct;
@@ -215,7 +217,7 @@ public class NetworkService
return responseStruct;
}
catch(Exception ex)
catch (Exception ex)
{
responseStruct.responseCode = -1;
responseStruct.responseText = ex.Message;