- Home /
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
Could you clarify why you think a coroutine is not viable? You say it's easy for the implementer to mess with your coroutines. What does that mean? Do you mean they could accidentally or intentionally replace a coroutine with another one they supplied?
Answer by MaxGuernseyIII · Sep 14, 2017 at 06:24 PM
Have you considered using WWW?
It has a constructor that will do a POST.
Answer by imsAL · Sep 20, 2017 at 02:10 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612134836im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Post Reqest with dictionary 1 Answer
How to use chunked transfer in UnityWebRequest? 0 Answers
Unity freezes when adding Task to List 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers