fix: HttpClient
HttpClient now sending requests & recieving responses as it should
This commit is contained in:
parent
242a55da13
commit
159f97f190
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using DatabaseModels.DataTransferObjets;
|
||||
using UnityEngine;
|
||||
|
||||
public class ScoreManager : MonoBehaviour
|
||||
@ -33,8 +32,6 @@ public class ScoreManager : MonoBehaviour
|
||||
PlayerEvents.OnWallTouched += ResetMultiplierAndReward;
|
||||
|
||||
GameStateManager.Instance.OnGameStateChange += OnGameStateChange;
|
||||
|
||||
var sbRecordDto = await HttpClient.Get<ScoreboardRecordDto>("https://localhost:7248/api/scoreboard/cuqmbr");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
@ -1,21 +1,29 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public static class HttpClient
|
||||
public static class HttpClient
|
||||
{
|
||||
public static async Task<T> Get<T>(string endpoint)
|
||||
{
|
||||
var getRequest = CreateRequest(endpoint, RequestType.GET);
|
||||
getRequest.SendWebRequest();
|
||||
|
||||
while (getRequest.isDone)
|
||||
while (!getRequest.isDone)
|
||||
{
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<T>(getRequest.downloadHandler.text);
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(getRequest.downloadHandler.text);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> Post<T>(string endpoint, object payload)
|
||||
@ -23,7 +31,7 @@ public static class HttpClient
|
||||
var postRequest = CreateRequest(endpoint, RequestType.POST, payload);
|
||||
postRequest.SendWebRequest();
|
||||
|
||||
while (postRequest.isDone)
|
||||
while (!postRequest.isDone)
|
||||
{
|
||||
await Task.Delay(10);
|
||||
}
|
||||
@ -49,10 +57,12 @@ public static class HttpClient
|
||||
return request;
|
||||
}
|
||||
|
||||
public enum RequestType
|
||||
private enum RequestType
|
||||
{
|
||||
GET = 0,
|
||||
POST = 1
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
DELETE
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user