Unity 3D Puts/Deletes http methods

后端 未结 1 1161
余生分开走
余生分开走 2020-12-10 20:31

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

相关标签:
1条回答
  • 2020-12-10 21:21

    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.

    0 讨论(0)
提交回复
热议问题