Post Requests without Coroutines

Hi all,

I need to write a script in which some POST requests are made.

At the moment, I’m using Unity coroutines with UnityWebRequest to send everything.
This works fine but I have one more constraint which makes using coroutine not quite right.

I cannot have a GameObject to run the coroutines on.
Ultimately, the output of what I’m doing is gonna to be a Unity Package.
That means if I rely on game objects, it is easy for the implementer to mess with my coroutines, change the name of my objects, or stop my requests, even not intentionally!
They could for exemple get my component with FindObject and simply call StopAllCoroutines(), which I obviously don’t want. It’s ok if my functions fail because of network problems but I don’t want that to be too intentional, or too easy.
The good thing is that I don’t need to go back to the main thread after sending my requests.

The best exemple of what I want is Unity’s builtin analytics.
These are sent at runtime, even on app quit, but still without any GameObject as DontDestroyOnLoad running coroutines.

I tried creating a DLL using System.Net.Http but as soon as I include it in my Unity project, it’s missing the imports… Manually adding System.Net.Http.dll did not fix the issue.

Anyone would be able to help me?

Thank you very much

Have you considered using WWW?

It has a constructor that will do a POST.

Try putting a file named mcs.rsp in the Assets directory with one line in it:

-r:System.Net.Http.dll

as suggested in this post:
https://forum.unity.com/threads/httpclient.460748/#post-2991963