Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't get status code from WWW.

Discussion in 'Windows' started by bboydaisuke, May 31, 2016.

  1. bboydaisuke

    bboydaisuke

    Joined:
    Jun 14, 2014
    Posts:
    67
    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:
    Code (CSharp):
    1. public void TestConnection()
    2. {
    3.     StartCoroutine(TestConnectionImpl());
    4. }
    5.  
    6. IEnumerator TestConnectionImpl()
    7. {
    8.     string url = "http://unity3d.com/";
    9.  
    10.     byte[] postData = null;
    11.     Dictionary<string, string> headers = new Dictionary<string, string>();
    12.  
    13.     using (WWW www = new WWW(url, postData, headers))
    14.     {
    15.         while (!www.isDone)
    16.             yield return www;
    17.  
    18.         if (!string.IsNullOrEmpty(www.error))
    19.             Debug.LogError("HTTP Communication error: " + www.error);
    20.         else
    21.         {
    22.             Debug.Log("HTTP Communication success.");
    23.        
    24.             System.Text.StringBuilder headerBuilder = new System.Text.StringBuilder();
    25.             if (www.responseHeaders.Count > 0)
    26.                 foreach (KeyValuePair<string, string> entry in www.responseHeaders)
    27.                     headerBuilder.AppendLine(entry.Key + "=" + entry.Value);
    28.  
    29.             Debug.Log(headerBuilder.ToString());
    30.         }
    31.     }
    32. }
    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.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    Can you submit a bug for this?
     
  3. bboydaisuke

    bboydaisuke

    Joined:
    Jun 14, 2014
    Posts:
    67
    Filed a bug report. I'll post the number after I received notification mail.
     
  4. bboydaisuke

    bboydaisuke

    Joined:
    Jun 14, 2014
    Posts:
    67
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    Thanks, we'll look into it.
     
  6. bboydaisuke

    bboydaisuke

    Joined:
    Jun 14, 2014
    Posts:
    67
    This bug is fixed in 5.3.6/5.3.5p7 as # 801998.
     
  7. psherif

    psherif

    Joined:
    Nov 19, 2013
    Posts:
    5
    Is it possible that this bug still persists on the WEBGL platform? I'm observing the same behaviour
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    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.
     
  9. f4bo

    f4bo

    Joined:
    Oct 7, 2014
    Posts:
    21
    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...
     
    Last edited: Mar 25, 2017