Hey community
I am having strange issue with web request response headers - they are listed but all of them are of null value, which is deadly in my case as i obviously need to read their data in ma app… The server response status itself is 200 though and also other additional data (json) which is part of an expected response are arriving pretty fine.
I am basically connecting to a custom Apiary api. When I test the request with same parameters in a browser it shows the headers content ok.
here is my C# code which i use to realize request from Unity (pretty stadard i think):
protected static IEnumerator PostUnityWebRequest(string url, string data)
{
byte[] bodyRaw = Encoding.UTF8.GetBytes(data);
UnityWebRequest request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST);
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
//request.useHttpContinue = false;
//request.redirectLimit = 0;
yield return request.Send();
if (request.isError)
{
Debug.Log("request error: " + request.error);
}
else
{
Debug.Log("server response status: " + request.responseCode);
Dictionary<string, string> responseHeaders = request.GetResponseHeaders();
AUTHORIZED = true;
isAuthorizing = false;
}
}
here is a screenshot showing the headers as they appear in the debugger:
here is how the same response headers appear in a web interface:
As I said, the body of the response arrives ok even in my unity request, I just cannot read the values of the headers (actually some headers are all missing too in my unity request as you can see)…
I am rather a noob regarding networking unfortunatelly, so after trying with new UnityWebRequest as well as legacy www class, I got a bit lost, even tried all other http methods (just to see if it could make any difference from standard POST). I have run through many related posts out there, from which i basically learned that there are some issues with unity networking api, particulary with redirecting but that doesn’t seem to be an issue in my case… I also tried to set different values for redirect limit in my web request. Some suggest to switch to 3rd party libs or using native .net classes instead… which i would like to avoid as it would mean to rewrite a major part of my async asset download managers etc…
So did enyone else here experience that, or does anyone have any clue what might be a possible cause?
I dont know what other info could i provide to help you help me, so please let me know:)
Thanks in advance guys!