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
IEnumerator GetTextWebRequest()
{
Debug.Log("********** Sending request WebRequest");
using (UnityWebRequest www = UnityWebRequest.Get("https://httpbin.org/get"))
{
www.SendWebRequest();
while(!www.isDone)
{
#if UNITY_EDITOR
if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
yield return null;
#else
yield return null;
#endif
}
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("********** Response received WebRequest: " + www.downloadHandler.text);
}
}
}
Using WWW
IEnumerator GetTextWWW()
{
Debug.Log("********** Sending request WWW");
using (WWW www = new WWW("https://httpbin.org/get"))
{
while(!www.isDone)
{
#if UNITY_EDITOR
if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
yield return null;
#else
yield return null;
#endif
}
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
}
else
{
Debug.Log("********** Response received WWW: " + www.text);
}
}
}
3485491–277386–HeadlessModeTest.zip (1.93 MB)