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

Unity Web Request in headless mode does not complete

Discussion in 'Editor & General Support' started by mediumTaj, May 5, 2018.

  1. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    When making a request using UnityWebRequest in headless mode, the request never completes. The same code using WWW finishes fine. Both sets of code work in the editor.

    Anybody ever see this before? Am I implementing UnityWebRequest incorrectly?

    Please see attached files and run the following scripts

    Run WebRequest in batchmode (see log file for output)
    "C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -nographics -silent-crashes -logFile %cd%\headlessTestWebRequest.log -projectPath %cd% -executemethod HeadlessModeTest.RunTestWebRequest


    Run WWW in batchmode (see log file for output)
    "C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -nographics -silent-crashes -logFile %cd%\headlessTestWWW.log -projectPath %cd% -executemethod HeadlessModeTest.RunTestWWW



    Using UnityWebRequest
    Code (CSharp):
    1. IEnumerator GetTextWebRequest()
    2.     {
    3.         Debug.Log("********** Sending request WebRequest");
    4.         using (UnityWebRequest www = UnityWebRequest.Get("https://httpbin.org/get"))
    5.         {
    6.             www.SendWebRequest();
    7.             while(!www.isDone)
    8.             {
    9. #if UNITY_EDITOR
    10.                 if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
    11.                     yield return null;
    12. #else
    13.                 yield return null;
    14. #endif
    15.             }
    16.             if (www.isNetworkError || www.isHttpError)
    17.             {
    18.                 Debug.Log(www.error);
    19.             }
    20.             else
    21.             {
    22.                 Debug.Log("********** Response received WebRequest: " + www.downloadHandler.text);
    23.             }
    24.         }
    25.     }
    Using WWW
    Code (CSharp):
    1. IEnumerator GetTextWWW()
    2.     {
    3.         Debug.Log("********** Sending request WWW");
    4.  
    5.         using (WWW www = new WWW("https://httpbin.org/get"))
    6.         {
    7.             while(!www.isDone)
    8.             {
    9. #if UNITY_EDITOR
    10.                 if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
    11.                     yield return null;
    12. #else
    13.                 yield return null;
    14. #endif
    15.             }
    16.  
    17.             if (!string.IsNullOrEmpty(www.error))
    18.             {
    19.                 Debug.Log(www.error);
    20.             }
    21.             else
    22.             {
    23.                 Debug.Log("********** Response received WWW: " + www.text);
    24.             }
    25.         }
    26.     }
     

    Attached Files:

  2. mediumTaj

    mediumTaj

    Joined:
    Feb 20, 2015
    Posts:
    28
    This may have been an issue with the endpoint I was testing. I am testing with a new endpoint and it seems to work.
     

    Attached Files: