I'm thinking of porting a JavaScript web app to C# Unity3D (Free / Personal Version) for an RPG I'm developing. I have an extensible, separate API built in PHP Laravel 5.1, which my game interacts with through jQuery http calls.
I need to continue making standard restful calls, get
, post
, put
, delete
, etc within Unity but have only found UnityEngine.WWW#
which makes gets
and posts
.
This SO Post shares the other available Unity3D http methods, but none which actually get all restful calls in one. I'm asking again because this was posted in 2012 and I haven't found any updates which satisfy this within the updated documentation.
There is Best HTTP Basic and Best HTTP for $45 and $55, but was thinking there would be other free options.
Am I missing something within Unity that allows for standard restful calls?
WebClient
and WebRequest
are both available in Unity and looks like it will only work with Pro Unity version just like any other API from the System.Net
namespace. I don't know if this restriction has changed in Unity 5. They support all those restful calls mentioned in your question.
Unity Added a new API called UnityWebRequest in version 5.2 with mobile platform support in 5.3. It was designed to replace WWW
and it supports all the restfull calls listed in your question. Below are example for each one. This is not a full example. You can find full examples in the link I provided above.
//Get
UnityWebRequest get = UnityWebRequest.Get("http://www.myserver.com/foo.txt");
//Post
UnityWebRequest post = UnityWebRequest.Post("http://www.myserver.com/foo.txt","Hello");
//Put
byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
UnityWebRequest put = UnityWebRequest.Put("http://www.my-server.com/upload", myData);
//Delete
UnityWebRequest delete = UnityWebRequest.Delete("http://www.myserver.com/foo.txt");
You can see complete example for each one including posting with json here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With