Consuming RESTful web services in Unity3d and learn how to use the Unity Engine Networking API

preview_player
Показать описание
Recently started learning how to consume RESTful web services while using the UnityEngine.Networking namespace. This API allows you to execute GETs, POSTs, PUTs, HEADs, and many more http methods.

In this video I walk you through consuming the .NET Core web service we built in the previous video to store and get player's from our in memory list of players.

Watch the previous video at:

Get realtime tips from me in Twitter

Subscribe to my videos & game releases newsletter

Blog
Рекомендации по теме
Комментарии
Автор

Subscribed.
I like how you brought us through the steps while explaining why you're doing it that way. I like when you brought up the stackoverflow post to help you through the issue you ran into. It makes it feel raw and like we're learning with you. What I like the most is you've stayed away from making you're tutorial feel like you already had the code written on a separate monitor and just copying what you did previously.
I haven't searched all of your videos, but if you haven't yet, a tutorial on securing your RESTful web services using jwt or something, and how to handle that in Unity would be amazing.
If us indie developers make a game that is getting a lot of players, we can almost guarantee that someone will try to hack it. I'd thumbs up that tutorial all day.
P.S. Thumbs up.

addictCoder
Автор

This video is a lifesaver. Thanks dude.

germancedres
Автор

First of all thank you @Dilmer Valecillos for these great videos. I wanted to tell you if anyone has had the problem regarding json and you get this error.


ArgumentException: JSON must represent an object type.
(System.String json, System.Type type) (at
They can solve them in this way.


string jsonResult =
string json =

PlayerList playerList =
callBack(playerList);

jimmyalexandermunozgutierr
Автор

This is a fantastic tutorial. Really appreciate it.

nash
Автор

Its a great helper, i use the form.data, but i was remember its to much easy use objet and then convert to Json.... thanks so much

AbibOlea
Автор

this awesome man, the only negative point is that you don't give the code, thank u any way

ismailtalhaoui
Автор

Hi Dilmer, thank you so much for this interesting tutorial! I don't know much about web servers, if I wanted to use express would it change a lot compared to your work?

ringostarkiller
Автор

Amazing video and an impress chanel man I really love it. I want to ask how would I have the server like online? meaning that the app is on another computer how would I access the data.

mujtabaalkhamees
Автор

Great tutorial, thanks a lot! Works like a charm! I do have two questions :-)


In the Post method it looks like you're doing things double. First you create the webrequest with the jsonData and then later on you create an uploadhander for that request, again with the jsonData. Same thing for the content-type, first you set the content-type for the request and then again for the uploadhandler. Is this double or is this how Unity requires it? And isn't the 'new UploadHandlerRaw' in line 77 overwriting the setting in line 76?


Second question is more fundamental: how about security? Your example is all localhost, so that's no problem, but when you expose this webservice at a public url anyone can add players, right? Do you have some thoughts, links, tutorials on how to handle webservice security in Unity?

jboss
Автор

I think you need to set the content type of the uploadHandler AFTER you overwrite with the new UploadHandlerRaw. So the lines 76 and 77 need to switch. Otherwise, the setting of content type will have no effect.

IliePandia
Автор

honestly this is how rest api access should be done, I am amazed that the unity API does things the way it does.... api calls should be done using JSON and how you construct your JSON body is important :/

devdylan
Автор

Thank you for a great tutorial. I have this the problem and don't know how to fix it, hope you can help me
ArgumentException: JSON must represent an object type.
(System.String json, System.Type type)
The error occured when I want to get a list of Json and turn them to an List object by using FromJson
ScoreList scores =
I noticed that my Json string was different your (my class don't have any ID): [{"Name":"Tom", "Value":1000}, {"Name":"Tippy", "Value":20000}, {"Name":"Carnation", "Value":9999}]

vilaptran
Автор

Hello, great series of videos! I watched the previous video as well.

Could you help me with something? I get this error:
ArgumentException: JSON must represent an object type.
(System.String json) (at
() (at
(IEnumerator enumerator, IntPtr returnValueAddress) (at

It hits on the "PlayerList playerList = line.

michaelchatzakis
Автор

how do you deal with security? To make sure people who call the service layer are actually aloud to call the webservice?

jamaismejamaisme
Автор

Hey, thank u for this,
Will u continue this ?
and can asp.net core be used to create online real time games ?

cuttlas
Автор

Fantastic tutorial.
That's what I need. Can I get the code github link, please?

mouhamadoubambandiaye
Автор

Hello, great video !
How would you do the same with ssl / https API ? =)

baptistelesaux
Автор

I get "Unknown Error" logged to the console after pressing play 6:55

chriswooohoo
Автор

That is great but is there a way to start the api server within unity?

tree
Автор

If I have any doubts on this I will ask youuu... Thank you

mbrdi