I have the following c# post request code:
public static string getJSON()
var client = new RestClient("");
var request = new RestRequest(Method.POST);
var httpWebRequest = (HttpWebRequest)WebRequest.Create("url")
request.AddHeader("cache-control", "no-cache");
request.AddParameter("undefined", "{\r\n\t\"application\": {\r\n\t\t\"id\":3\r\n\t},\r\n\t\"luminaire\": {\r\n\t\t\"id\":60\r\n\t},\r\n\t\"room\": {\r\n\t\t\"length\":" + roomSize.x + ",\r\n\t\t\"width\":" + roomSize.z+ ",\r\n\t\t\"height\":"+roomSize.y+",\r\n\t\t\"discretizedPitch\":{\r\n\t\t\t\"x\":0.6,\r\n\t\t\t\"y\":0.6\r\n\t\t}\r\n\t}\r\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
return response.Content;
Now this works in normal unity, however when I make a webbuild this encounters null related problems.
I also tried rewriting the code into unitynetwork code (using Sending http requests in C# with Unity)
public static void getJSON(){
var s = StartCoroutine(PostRequest("url", "\"application\": {\"id\":3},\"luminaire\": {\"id\":60},\"room\": {\"length\":" + roomSize.x + ",\"width\":" + roomSize.z + ",\"height\":" + roomSize.y + ",\"discretizedPitch\":{\"x\":0.6,\"y\":0.6}}"));
}
string res = "";
IEnumerator PostRequest(string url, string json)
{
var uwr = new UnityWebRequest(url, "POST");
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
uwr.SetRequestHeader("Content-Type", "application/json");
//Send the request then wait here until it returns
yield return uwr.SendWebRequest();
if (uwr.isNetworkError)
{
Debug.Log("Error While Sending: " + uwr.error);
res = "error";
}
else
{
res = uwr.downloadHandler.text;
Debug.Log("Received: " + uwr.downloadHandler.text);
}
}
however this just throws a server 500 error rather than anything useful, anybody know how to either port the first code into unitynetwork code or why the first code gives a null exception in webgl (but not in normal code)?