Search Unity

Simple GET request with UnityWebRequest fails on iOS

Discussion in 'Connected Games' started by DarkVerse, Jul 15, 2019.

  1. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Hi All,

    I have a simple GET request using UnityWebRequest that returns a JSON string from a URL. It works fine on Android but returns "Unknown Error" with a response code 0 on iOS. I have searched the forum and web for related issues but everyone seems to be talking about issues with POST. I am just doing a GET and it is very vanilla, ie (from memory as I am not in front of my dev machine)
    UnityWebRequest www = UnityWebRequest.Get("https://some-domain.org/?query=Production&start=0");
    yield return www.SendWebRequest();
    if (www.isError || www.isNetworkError) {
    Debug.Log(www.error);
    }

    Now this works fine on Android but not iOS. The only thing non-standard, and not covered in the examples, is the use of parameters in the URL. But I assume that is OK and, as I say, works in Android. Also note I am using https and not http (which should actually present less problems on iOS). I shall continue testing, eg remove parameters, but it is a slow process (build, transfer to XCode, build etc) and I am wondering if anyone has seen this issue before (again for GET not POST). This seems to be such a simple thing to do but is not working on iOS. I have tried allow unauthorised http and other settings in XCode but nothing helps.

    I am using Unity 2018.3.12 and the iPhone testing on is iPhone 6. It does not have a SIM but is connected to a WiFi network and I can successfully browse to the URL in question and see the correct response. I do a test for network connectivity before sending the request, which returns that the internet is reachable.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    Is that same URL accessible via HTTP instead of HTTPS?
    Trying to rule out the security.
    Also, have you tried Unity 2019.1? UWR backend was rewritten in that release.
     
  3. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    I have been reluctant to upgrade as I am close to a release deadline and going to 2019.1 may introduce more problems to solve, eg it will force me into Unity Hub and with Hub it seems that you cannot run Unity as Administrator. I may have to setup a test environment tho on another machine and try it.

    I will try http and see, but I think it might have more to do with being on a WiFi and not using mobile data so I am trying to find a test iPhone with a SIM.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    That sounds strange. All my tests on iPhone we done using WiFi on devices without SIM.
    My suggestion was not to upgrade Unity, just try to perform the same request on newer version to see, if it's an issue with the backend on 2018.3 (which was rewritten in 2019.1).
     
  5. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Oh OK, thanks for that. It is good to know that it should work on WiFi without SIM, so I can eliminate that.
    Yes, I will try and setup a minimal test case on 2019.1 and see if it works.
    Thanks for the input.
     
  6. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    I tried on 2019.1.10f1 and it works as expected. I should have started my minimal test in 2018.3 first to see that it wasn't working (in case it is something else in my project) then go to 2019.1.10.
    Before upgrading I might do that just to make sure it is a problem in 2018.3 and not something else.
     
  7. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Ok, I setup a clean minimal project in 2018.3.12 that just sends the UnityWebRequest with the exact same code I used in the 2019.1.10 project. It works in 2019.1.10 but not in 2018.3.12 so it looks like the rewrite of the backend of UnityWebRequest has solved the problem. Now I need to decide if I risk other unknowns by upgrading the project, maybe to be safe I will do that in a fork of the project on a different machine.
    Thanks for your help @Aurimas-Cernius
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    Could you report a bug?
    This has to be fixed in 2018.4 and you'll have an option of a less risky upgrade.
     
  9. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Shall do. Is it possible that it has already been fixed in 2018.4? Should I verify that it is broken in 2018.4 first?
     
  10. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    I don't remember fixing it, so I think you can just submit a bug, our QA will check if reproduces anyway.
     
  11. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Bug report submitted. Case number 1170159
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
  13. DarkVerse

    DarkVerse

    Joined:
    Jan 9, 2017
    Posts:
    38
    Ok, so I got a reply to say it has been fixed in 2019.1 and up!
    So I have upgraded (which I was trying to avoid) and now, predictably, I cannot build to iOS at all.
    Very frustrating.