Untitled

 avatar
unknown
plain_text
2 years ago
1.3 kB
10
Indexable
public IEnumerator GetAsyncTest(string urn, object data = null)
    {
        var request = UnityWebRequest.Get(urn);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        request.SetRequestHeader("Authorization", "MY TOKEN");
        request.SetRequestHeader("Accept", "*/*");

        if (data is not null)
        {
            var bodyRaw = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data));
            request.uploadHandler = new UploadHandlerRaw(bodyRaw);
        }

        Debug.Log($"req err : {request.downloadHandler.error}");
        Debug.Log($"req data : {request.downloadHandler.data}");
        Debug.Log($"req text : {request.downloadHandler.text}");


        // Log request details
        Debug.Log($"Request URL: {urn}");
        if(data != null)
        {
            var test = JsonConvert.SerializeObject(data);
            Debug.Log($"test : {test}");
        }
        else
        {
            Debug.Log($"ERROR EMPTY");
        }
        yield return request.SendWebRequest();

        Debug.Log($"Simple Response Code: {request.responseCode}");
        Debug.Log($"Simple Response Text: {request.downloadHandler.text}");
    }
Editor is loading...
Leave a Comment