0

I've got an Android app I'm building with Unity that logs info on a simple python http server (hosted on a Digital Ocean Droplet). Here's my coroutine for poking the server:

IEnumerator pokeServer()
{
    Debug.Log( "Establishing Server Connectivity..." );
    using( var www = UnityWebRequest.Get( ServerURL ) )
    {
        Debug.Log( "Send Web Request" );
        ServerStatus = ConnectionStatuses.AttemptingToConnect;
        yield return www.SendWebRequest();

        if( www.isNetworkError  ||  www.isHttpError )
        {
            if( www.isNetworkError )
            {
                Debug.Log( "NETWORK ERROR: " + www );
            }
            else
            {
                Debug.Log( "HTTP ERROR: " + www );
            }
            ServerStatus = ConnectionStatuses.Unavailable;
        }
        else
        {
            Debug.Log( "Success!  Server available!" );
            ServerStatus = ConnectionStatuses.Connected;
        }
    }
}

If I run this on the Unity Editor, everything works fine. I can get a response from my server without issue. If I build and run this on an Android, the request is not sent to my server and I get no error message. The last line in the above code that's run is "yield return www.SendWebRequest();"

I've looked at the logcat, and there's no error. My server never gets any requests. However, if I poke "https://www.google.com," I do indeed get a response. This leads me to believe that this is some sort of http vs https issue, but I have no idea where to start. This code has been working for me for a very long time. Any advice would be very welcome!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • What version of Android is your device? What is your target API level? – Retired Ninja May 01 '19 at 17:50
  • I would guess if you target an API lower than 28 and/or add a Network security configuration to allow non-https traffic you'll be fine. https://developer.android.com/about/versions/pie/android-9.0-changes-28 – Retired Ninja May 01 '19 at 17:56
  • I'm using and targeting Marshmallow 6.0, API level 23. Could this still be related? – Penn Neurology May 01 '19 at 18:05
  • It's possible. I know we use a security config for debug builds to allow us to run through a proxy and before 6 we didn't have to. Probably worth a shot for troubleshooting purposes. – Retired Ninja May 01 '19 at 18:13
  • 1
    Thanks for your response, Retired Ninja. You may have saved me a headache; we're going to get new phones soon and I probably would have run into that problem on my own. – Penn Neurology May 02 '19 at 14:55

1 Answers1

0

I'd been using this phone from University of Pennsylvania's wireless network. It turns out that I can make an http request from a desktop but I can't do it from a phone. I took one of the devices home and tried it from my personal wifi and it all worked fine.