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. Dismiss Notice

Why is UnityWebRequest so flaky?

Discussion in 'Scripting' started by juliang, May 6, 2020.

  1. juliang

    juliang

    Joined:
    Nov 25, 2008
    Posts:
    98
    It's frequently unable to connect to a database - connection timeout. At the same moment, the same request via a curl command has no problem. Usually if I quit and restart the editor it'll be ok. Not always, though, and after a half dozen sends then it starts timing out on the connect again. And again, while curl has no problem. Is there something that needs to be set somewhere? Is there a good alternative?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    You could try the standard .NET HttpClient.
    UnityWebRequest is deprecated and planning to be replaced with something in the future, but as far as I know, there isn't any information about when a replacement might be coming.
     
  3. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    I don't think unitywebrequest is deprecated

    Are there specific problems you have with UWR? Have you logged a bug?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Can you show the code you use to connect?
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    No it's not. The was an issue in our documentation page - the deprecation notice on top of it was about deprecation of UNet only, UWR is not pat of UNet.
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Good to know, thanks.
     
  7. juliang

    juliang

    Joined:
    Nov 25, 2008
    Posts:
    98
    Code (CSharp):
    1.   IEnumerator TestConnection(int ignore)
    2.     {
    3. [INDENT]request = UnityWebRequest.Get($"{neo4jManager.Instance.ServerAddress()}/user/neo4j");
    4. request.SetRequestHeader("AUTHORIZATION", ConstructAuthorization());
    5. request.timeout = 3;
    6. yield return request.SendWebRequest();
    7. if (request.error != null)
    8. [INDENT]DisplayError(request.responseCode, request.error);[/INDENT]
    9. else StartCoroutine(DisplayResults(request.responseCode, request.downloadHandler.text));[/INDENT]
    10. }
    Everything is on the same computer, so 3 seconds is much longer than needed for the connection. The curl command actually completes the cycle in less than 1.