14

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

Hacketo
  • 4,978
  • 4
  • 19
  • 34

2 Answers2

1

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).

peterept
  • 4,407
  • 23
  • 32
  • this code actually use `responseHeaderString` as `text`, and `responseHeaderString` does not contain HTTP status. So the header construction may not fill this condition, I'll re-check when I can with wireshark but I'm sure that the response is the same for each device and is HTTP compliant. – Hacketo Oct 28 '15 at 22:23
  • Unity messes with the response so `responseHeaderString` may not be a true indication of what the server is sending. – peterept Oct 28 '15 at 22:34
  • with that wireshark capture, was it running as a proxy and your windows phone was set to communicate via it? can you share the servers URL ? – peterept Nov 05 '15 at 12:57
  • I'm working on an IMac so I share the wifi to the devices, like a proxy. can't share the servers URL, I try to make this bug with a public url and simple code. – Hacketo Nov 05 '15 at 13:32
  • ok, great. Also try fetching your URL with: https://redbot.org (it might show up something incorrect) – peterept Nov 05 '15 at 13:45
  • I edited my post with a sample code to reproduce the bug using google – Hacketo Nov 05 '15 at 13:57
  • Wow, that's an insane repro. Anything in www.error ? I don't have a windows phone to verify on. – peterept Nov 05 '15 at 23:22
  • www.error is null, as stated in my comment on my post. That's why I asked for bug confirmation too, a simple http request with no weird configuration server side. – Hacketo Nov 05 '15 at 23:28
  • I don't see any bugs like that filed. It would be interesting to know if it is on other windows phones too. When I'm not using www I use uniweb: https://www.assetstore.unity3d.com/en/#!/content/483 – peterept Nov 05 '15 at 23:44
0

Try reading the www.error before looking for the STATUS header.

// Construct the response object
string error = www.error;
if (error == null) {
    if (www.responseHeaders.ContainsKey("STATUS")) {
        string [] status=www.responseHeaders["STATUS"].Split(' ');
        if (status.Length>2 && status[2] != "OK") {
            error = www.responseHeaders["STATUS"];
        }
    }
}
Ian Pilipski
  • 507
  • 3
  • 8