Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WWW.responseHeader["STATUS"] does not exists

I already asked on answers.unity3d but as there is no response I'll ask on SO too..

I'm not able to retrieve the http status of a response on the WWW object on Windows Phone 8 and Windows RT 8.1 (while it's ok on IOS/Android).

www.responseHeader["STATUS"] does not exists and the hidden field _responseHeaderString does not contain as first line

HTTP/1.1 200 OK


responseHeaderString :

Server: nginx
Date: Wed, 21 Oct 2015 07:44:36 GMT
Last-Modified: Mon, 07 Sep 2015 11:43:46 GMT
Connection: keep-alive
Expires: Fri, 20 Nov 2015 07:44:36 GMT
Cache-Control: max-age=2592000
Cache-Control: public

responseHeader :

{
    "SERVER"       : "nginx"
    "DATE"         : "Wed, 21 Oct 2015 07:44:36 GMT"
    "LAST-MODIFIED": "Mon, 07 Sep 2015 11:43:46 GMT"
    "CONNECTION"   : "keep-alive"
    "EXPIRES"      : "Fri, 20 Nov 2015 07:44:36 GMT"
    "CACHE-CONTROL": "public"
}

Sample code to reproduce : (tested on an empty new project)

WWW www = new WWW("http://www.google.com");

yield return www;

Debug.Log("Google Status : " + www.responseHeaders.ContainsKey("STATUS")); // False
Debug.Log(www.text); // <doctype ...
Debug.Log(www.responseHeaders["STATUS"]); // KeyError

Am I missing something or is there someone that can confirm this as a bug ?

Edit: Still not able to retrieve the http status with the latest 5.3

like image 412
Hacketo Avatar asked Oct 20 '15 11:10

Hacketo


People also ask

What status code will I get if the API is not available?

404 Not Found This is by far the most common HTTP status code you can get. It indicates that the URL you used in your request doesn't exist on the API server, or origin server. While this is a 4XX error, which usually means something on the client-side is wrong, this can also indicate a server problem.

How do you set a status code in HTTP response?

Methods to Set HTTP Status Code Sr.No. This method sets an arbitrary status code. The setStatus method takes an int (the status code) as an argument. If your response includes a special status code and a document, be sure to call setStatus before actually returning any of the content with the PrintWriter.

How do I check my HTTP status code?

Just use Chrome browser. Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc.


1 Answers

Your network server is probably responding with a different (unexpected) response to each device. For various reasons such as the user agent string, which could lead the WWW class to not get the STATUS.

Firstly, I would install a proxy so you can see exactly what the phone sends and what the server raw response is. Either Charles Proxy (mac/windows) or Fiddler (windows) are great.

Here is the actual code that Unity WWW class is using to generate status:

        if (num++ == 0 && text.StartsWith("HTTP"))
        {
            dictionary["STATUS"] = text;
        }

Ref: https://github.com/MattRix/UnityDecompiled/blob/master/UnityEngine/UnityEngine/WWW.cs#L483

From the proxy it should be clear what is happening. If not, post the request and response here (as raw).

like image 128
peterept Avatar answered Oct 04 '22 23:10

peterept