WWW.responseHeader["STATUS"] does not exists
Asked Answered
B

2

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

Beast answered 20/10, 2015 at 11:48 Comment(6)
Just to verify - this is a HTTP(S) request, and not a file:// or other protocol? The header would suggest HTTP, but these things tend to get emulated in some environments, and I did have this behavior before when using a file:// protocol on android.Bellbird
it's a simple http request to download a file, so I need 304/200 information :)Beast
Does your www object .error come back without any errors?Scopas
@MXD no, www.error is null.Beast
Unity 5.2.2 came out yesterday if you want to give that a try.Bertilla
updated the project to 5.2.2 but STATUS is still missing :/Beast
N
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).

Noria answered 28/10, 2015 at 21:54 Comment(9)
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.Beast
Unity messes with the response so responseHeaderString may not be a true indication of what the server is sending.Noria
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 ?Noria
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.Beast
ok, great. Also try fetching your URL with: redbot.org (it might show up something incorrect)Noria
I edited my post with a sample code to reproduce the bug using googleBeast
Wow, that's an insane repro. Anything in www.error ? I don't have a windows phone to verify on.Noria
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.Beast
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: assetstore.unity3d.com/en/#!/content/483Noria
L
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"];
        }
    }
}
Loyal answered 11/5, 2016 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.