Can't get status code from WWW

Hello,

I need to get HTTP STATUS CODE on web access using WWW class. I tried to parse status code from HTTP Response Header “STATUS”. That works perfect on Unity Editor.
However, if I build it to Windows Store App (Universal 10), I can’t get STATUS header because WWW.responseHeaders doesn’t have STATUS on WSA.
Please help me to get status code from WWW on WSA.

Repro code:

public void TestConnection()
{
    StartCoroutine(TestConnectionImpl());
}

IEnumerator TestConnectionImpl()
{
    string url = "http://unity3d.com/";

    byte[] postData = null;
    Dictionary<string, string> headers = new Dictionary<string, string>();

    using (WWW www = new WWW(url, postData, headers))
    {
        while (!www.isDone)
            yield return www;

        if (!string.IsNullOrEmpty(www.error))
            Debug.LogError("HTTP Communication error: " + www.error);
        else
        {
            Debug.Log("HTTP Communication success.");
       
            System.Text.StringBuilder headerBuilder = new System.Text.StringBuilder();
            if (www.responseHeaders.Count > 0)
                foreach (KeyValuePair<string, string> entry in www.responseHeaders)
                    headerBuilder.AppendLine(entry.Key + "=" + entry.Value);

            Debug.Log(headerBuilder.ToString());
        }
    }
}

Repro Steps:

  • Put the code above and call TestConnection() in your project.
  • Run the code in Unity Editor.
  • See the Console output. Headers start with “STATUS=HTTP/1.1 200 OK”. This is expected.
  • Build the project to Windows Store App. Select “Universal 10” for SDK.
  • Run the project in Visual Studio.
  • See Debug output. Headers start with “SERVER=…” and there is no “STATUS” header. This is NOT expected.

Can you submit a bug for this?

Filed a bug report. I’ll post the number after I received notification mail.

Filed case # 801998.

Thanks, we’ll look into it.

This bug is fixed in 5.3.6/5.3.5p7 as # 801998.

Is it possible that this bug still persists on the WEBGL platform? I’m observing the same behaviour

WebGL has it’s own implementation for WWW, so it’s possible. Submit a bug report.
You can also switch to UnityWebRequest, that should work there.

I’m getting a weird behavior too on this matter - the weird thing is that this issue just happens on an android’s gingerbred 2.3.3 device (the app is targeted to this release) but it works running from Unity editor and from an android device but with kitkat.
BTW I’m working on U5.4.4f1
Addendum: I’m noticing also that between the 3 cases (PC, android gingerbread and kitkat) the headers number differ: while in GB STATUS is missed completely, in KK there is and there is also a weird NULL code with the same content as STATUS (HTTP/1.1 200 OK) and a code [X-ANDROID-RECEIVED-MILLIS] that I don’t see in PC or GB. Go figure…