UnityWebRequest works only in the editor, not in the standalone build

UnityWebRequest works only in the editor, not in the standalone build


-1

I noticed that UnityWebRequest is working BUT only in editor mode.
When I build the game (in this case Im building Standalone for Windows 10) the response code is "200", but the {response.webRequest.downloadHandler.text} is equal to: "{"Errors":[{"extensions":{"internal":{"no connection to the server…. ecc…

I knew that if response code equals 200 it means the connection is correctly established…can someone help me to figure out what im doing wrong?

this is the way I make the request…

UnityWebRequest request = CreateApiPostRequest(URL, query);       
UnityWebRequestAsyncOperation response = request.SendWebRequest();

public UnityWebRequest CreateApiPostRequest(string actionUrl, object body = null)
{
    
    return CreateApiRequest(actionUrl, UnityWebRequest.kHttpVerbPOST, body);
}


UnityWebRequest CreateApiRequest(string url, string method, object body)
{
    string json = JsonUtility.ToJson(body);

    UnityWebRequest request = new UnityWebRequest();
    request.url = url;
    request.method = method;
    request.downloadHandler = new DownloadHandlerBuffer();
    request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(json));
    request.SetRequestHeader("Accept", "application/json");
    request.SetRequestHeader("Content-Type", "application/json");
    request.SetRequestHeader("secret", mySecret);
    request.timeout = 60;

    return request;
}

I also tried with .NET classes like HttpWebRequest but I have the same result, it is so weird…in the editor it works fine.
I tried also to show the json string in the build and it is correct, maybe I am missing something..
can someone help me please?

EDIT:
The issue was the Deserialization, which happens immediately after the response is received, and the reason for that I was not using JsonUtility from Unity or another package developed for Unity.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *