HTTP requests with Magic Leap

Unity Editor version : 2022.2.12f1
ML2 OS version : 1.12.1
Unity SDK version : 2.2.0
Host OS : Windows 11

I made a Flask API to handle requests to Gemini and send responses back to my application. The API works fine in the Unity editor, and I am able to send and receive. However, I run into problems when building to the headset and trying to send and receive from there. I made sure that both my desktop and the headset were connected to the same wifi and also added this line to my manifest (uses-permission android:name="android.permission.INTERNET"). However, I always get a "cannot connect to destination host" error. Are there some settings or other permissions I have to enable in order to allow an insecure connection from the headset? Or are permissions not the origin of the issue? I also tried using the IP address in the API URL, but that didn't work either. I am new to Magic leap and Unity so this might have an obvious solution that I am overlooking.

I recommend launching the log feature through the Magic Leap Hub > Device Bridge the filter by entering "Unity". Also add a few try & catches around the areas with a generic exception.

Something like this:

    // HTTP Request GET / POST / ETC
catch (Exception e)

Then in the log, you will be able to see what error is getting generated, either from you mini web service or from the device.

1 Like

Thanks for the response! I've been watching some of your video tutorials and really enjoy them.

I am using a yield return so I was not able to put it in a try catch, but I put in an if statement:

txt.text = "before send...";
yield return request.SendWebRequest();
txt.text = "sending...";
// Handle the response
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.DataProcessingError)
    Debug.LogError("Error: " + request.error);
    txt.text = "error..." + request.error;

I try to connect to http://[IP]:8000/ and the request ends up timing out on the headset (but works in Unity editor). I watched one of your videos and tested with with an http url and was able to connect on the magic leap for that, so I guess it isn't a settings/privacy issue. However, I'm a bit lost on as to why the connection is timing out and if its an issue with the windows firewall or the port I'm using. Any insight would be appreciated!

Check "Internet Access" setting and see if it is enabled:


It turns out it was a firewall issue (I am working on university computers). The issue is resolved now. Thank you for your help!