Search Unity

UnityWebRequest always return empty response with no error

Discussion in 'VR' started by ivan20071, Mar 13, 2018.

  1. ivan20071

    ivan20071

    Joined:
    Nov 15, 2017
    Posts:
    29
    Hi,
    With Unity 2017.3.1p3 and Master build
    UnityWeResponse always return empty response with no error.
    Debug build is ok
    Does anybody experience this issue?
    Thank you
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello, can you file a bug with a min repro project and repro steps please?
     
  3. ivan20071

    ivan20071

    Joined:
    Nov 15, 2017
    Posts:
    29
    Hello,
    I tried with a mini repro project and It works but with my app I had to recompile it with 2017.3.1p1.
    Anyway, the configuration is this:
    1) Mixed reality project built with MRTK 2017.2.1.1
    2) Unity 2017.3.1p3
    3) HTTP request made with this code:

    private IEnumerator ClickUnityWebRequest()
    {
    using (var www = UnityWebRequest.Get(Url))
    {
    www.chunkedTransfer = false;
    var response = www.SendWebRequest();
    while (!response.isDone) yield return null;

    Debug.Log($"isNetworkError: {www.isNetworkError}");
    Debug.Log($"isHttpError: {www.isHttpError}");
    Debug.Log($"responseCode: {www.responseCode}");
    Debug.Log($"error: {www.error}");
    Debug.Log($"Response: {www.downloadHandler?.text}");
    }
    }

    4) With unity player and VS project in debug mode was ok
    5) VS project and Master X64 the response was empty

    When I will try again I will let you know.
    Thank you
     
  4. johnkallen

    johnkallen

    Joined:
    Dec 20, 2015
    Posts:
    2
    Here is my code (requestData is an Object):

    string jsonString = JsonUtility.ToJson(requestData);
    Debug.Log("jsonString:" + jsonString);
    byte[] bytes = Encoding.UTF8.GetBytes(jsonString);

    using (UnityWebRequest www = new UnityWebRequest (URL)) {
    www.method = UnityWebRequest.kHttpVerbPOST;
    www.uploadHandler = new UploadHandlerRaw (bytes);
    www.downloadHandler = new DownloadHandlerBuffer ();
    www.uploadHandler.contentType = "application/json";
    www.chunkedTransfer = false;

    yield return www.SendWebRequest ();

    if (www.isNetworkError || www.isHttpError) {
    Debug.Log (www.responseCode);
    Debug.Log (www.error);
    } else {
    Debug.Log ("Post complete! RespLength:" + www.downloadHandler.text.Length);
    Debug.Log ("text:" + www.downloadHandler.text);
    }

    }
     
  5. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    same here any fix for this? Using unity 2018.0.3f2
     
  6. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    Having same problem on 2017.3.10f1 while trying to run the coroutine ivan20071 posted with the url set to: http://quotes.rest/qod.json?category=inspire

    Only difference is I initiate the request using an EditorWindow button that sets a coroutine var and registers a delegate as follow:
    Code (CSharp):
    1. if(GUILayout.Button("ButtonName") {
    2.    coroutine = GetQuote();
    3.    EditorApplication.update += EditorUpdate;
    4. }
    and then EditorUpdate() does this:
    Code (CSharp):
    1. void EditorUpdate() {
    2.     if (coroutine == null) {
    3.         Debug.Log("Coroutine is null, deregistering delegate");
    4.         EditorApplication.update -= EditorUpdate;
    5.     } else {
    6.         Debug.Log("Coroutine is NOT null");
    7.         coroutine.MoveNext();
    8.     }
    9. }
     
    Last edited: Apr 5, 2019