I am currently using Unity's WWW to call my backend and it is working except this:
I need to get the error response head and body, but not sure how to accomplish this:
WWW www = new WWW(url_base + param[0]);
yield return www;
if (www.error == null)
{
Debug.Log("Perfect!");
}
else
{
// Needs to handle the errors from header and body
Debug.Log("ERROR: "+www.error);
}
Is there anyway to retrieve the header and body from the www?
If yes, discard the second part of the question, else...
Is this possible to accomplish by using the UnityWebRequest?
And if I am using UWR, is this possible?
I have some www's looking like this:
www = new WWW(url_base + param[0], Encoding.UTF8.GetBytes(param[1].ToString()), CreateHeader(false));
I would advise you to go with the unity web request for handling backend in unity since www will be removed in newer versions of unity. Coming back to your question: you can get all the response headers using the public method of unity web request as given below:
UnityWebRequest unityWebRequest;
unityWebRequest.GetResponseHeaders(); // it returns the list of all headers
You can also get the error response using unity web request as given below:
unityWebRequest.error; //it returns the error response
I would advise you to go with unity web request because it is the preferred and future of unity for handling backend
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html