Question by
mickey-evers · Mar 24, 2018 at 06:09 PM ·
jsonapiwebrequestbodyrest
UnityWebRequest read body response
Hy, I am trying to read the body response from a call to a server. The problem is that I get this error: NullReferenceException: Object reference not set to an instance of an object
I can read the header when I do the UnityWebRequest call. The person gets added to the database on the server. I just can't get to the body of the respons. I need it so i can use the id in the app. Can sombedoy help me?
this is my code:
public void startButton()
{
StartCoroutine(CreateUser());
}
IEnumerator CreateUser()
{
testclass myObject = new testclass();
myObject.email = "testmail@test.be";
myObject.password = "svhdshkhqfgv";
string jsonStringTrial = JsonUtility.ToJson(myObject);
byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(jsonStringTrial);
var request = new UnityWebRequest("https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=serverapi", "POST");
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(request.error);
}
else
{
Debug.Log("Form upload complete!");
Debug.Log(request.responseCode);
Debug.Log("server response status: " + request.responseCode);
Dictionary<string, string> responseHeaders = request.GetResponseHeaders();
Debug.Log(responseHeaders.Keys);
foreach (KeyValuePair<string, string> entry in request.GetResponseHeaders())
{
Debug.Log(entry.Value + "=" + entry.Key);
}
Debug.Log(request.downloadHandler.text);
}
}
Comment
Your answer
Follow this Question
Related Questions
UnityWebRequest, C# request.accept equivalent? 1 Answer
Issue with sending Json via UnityWebRequest 0 Answers
UnityWebRequest, C# request.accept equivalent? 0 Answers
Pasting data from JSON into UI 0 Answers