How To WEB REQUESTS IN UNITY

Nicholas Namusanga
3 min readAug 25, 2023

Unity is the most evolved game engine when it comes to being able to interact with servers, store information and retrieve it.

Web requests are messages sent by a client (such as a web browser or your Unity game) to a server to request resources or perform actions over the internet using the HTTP protocol.

They are very important when saving player info, retrieving game info and also starting new servers when players join. Today I will show a new technique that makes it drastically easier to send Web Requests in Unity and takes the code needed to send a Web Request all the way down to just three lines and makes massive improvements to the default methods of sending requests in Unity.

Much easier Web Requests

Downloading Unity Post

First we need to download the Web Request Engine, you can do this by simply heading over to their GitHub.

When it’s downloaded, simply import the folder into your Unity Project.

Send a Web Request

Once your done, let’s take a look at how you can send a request very quickly using Unity Post.

As you can see, sending a request using Unity Post is super easy, all the heavy lifting is pretty much done for you. Now let’s take a look at a more complicated case where we add some parameters to our request.

Here as you can see on line 3 we add a parameter to the header of the request, allowing us to let the sever know some more information about we want to get from it.

Then we also use a custom authentication which would come in handy in cases where a server need some sort of authentication to allow us to make some requests.

Post Window

Finally, the true power of Unity Post can be unleashed in the Unity Post Window. This is a super powerful window that allows you to test requests with different parameters before sending them. Open it by going to Web Requests → Open Post Window in your Editor.

Unity Post Window

The window allows you to test the request you want to send before sending it to see if you get a result, meaning you don’t need to enter Play Mode before testing your web request.

Unity Post Window

Here is an image of the Unity Post Window being used to send a request to a remote server and displaying the request in the output.

With all that sorted we are good to go, now you can use Unity Post to make requests to remote servers. Be sure to join my Discord as well for updates to this post.

--

--