4

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?

Community
  • 1
  • 1
user3871
  • 12,432
  • 33
  • 128
  • 268

1 Answers1

8

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.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Just a Unity 5 update - these are free features and seem to be fully supported in Unity 5.4+. I'm using them in Unity 5.3 (listed as experimental) and they're working. – hubatish Sep 14 '16 at 17:35
  • @hubatish `UnityWebRequest` is free and I did not say it needs pro. `WebClient` and `WebRequest` are what need pro but not anymore in Unity 5. FYI, `UnityWebRequest` is no longer experimental in 5.4. You should be using 5.4 by now. It fixed many problems with it. – Programmer Sep 14 '16 at 17:40