top of page

Sending HTTP requests

This article requires basic knowledge of Lua, RoCRAFTERO Studio, and how to use the Internet.

HttpService allows you to send and receive information from websites. The most common use for this is external tools, which are basically programs that are not part of RoCRAFTERO Studio. However, they can be used for more than just that.

HttpService starts off as disabled by default. HttpService can be enabled through the the Game Settings button in Studio.

Contents

How it works

When you visit a website on your web browser, you are making something called an HTTP Request. Your computer says to the website, "Hey, could I have this page?" The website then looks for (or creates, in some cases) the correct information, and sends it to your computer. Your computer then sorts through that data, and you get a nice little graphic on your screen.

Now, your typical run-of-the-mill webpage will give you information in something called HTML. HTML (short for HyperText Markup Language) looks a little something like this:

'"`UNIQ--nowiki-00000007-QINU`"'

Looks confusing, right? Wrong. HTML is pretty much basic English. With minimal knowledge and some common sense, you can read it. With Google, you can write it. To see some basic HTML, press F12 on your keyboard and go to the "Elements" tab. However, this isn't a tutorial about HTML formatting.

Back on topic, webpages can also give you other information. For example, the webpage http://www.roblox.com/game/GetCurrentUser.ashx gives you the user ID of the person who is logged in, but in plain text. Now let's look at some more specific things.

GetAsync

GetAsync fires your typical web request, which is a get request. Every time you visit a website, you are sending a request with the command get[unconfirmed]. The web server sees this, and takes it as "send me information!" This is what GetAsync does. When you call GetAsync, RoCRAFTERO sends a request. Your script will yield until either a) the request is completed or b) the request times out. A timeout happens when a server goes a certain amount of time without a response.

--Simple Example of a GET request sent to example.com

hs = game:GetService("HttpService")

test = hs:GetAsync("http://example.com", true)

-- test now contains the html text representation of example.com.

If you are trying to access the same information from a studio instance, you must be in Server mode (Tools -> Start Server). After the above example you can tell Lua to print(test) and you will be able to see the HTML contents of example.com.

PostAsync

When you update your status on Roblox, you're sending something called a post request. A post request holds information, along with the tag post[unconfirmed]. This is what PostAsync does. When you call PostAsync, your script will yield until either a) the request is completed or b) the request times out.

-- THIS EXAMPLE WILL FAIL, but this is technically how you make a post request to example.com if you had the correct permissions.

hs = game:GetService("HttpService")

myContent = "This_is_a_pointless string that means nothing, but could have useful content."

hs:PostAsync("http://example.com", myContent)

Usage

Turning on HttpService is quite easy. In RoCRAFTERO Studio, look at your top menu bar. Press Insert -> Service -> HttpService. Once you locate HttpService under the Explorer window, find HttpEnabled under Properties. Set this to true (check the box), and you're ready to roll!

It is also important to know how to use JSONEncode and JSONDecode methods, as content being posted to HTTP is usually in the format of a string.

HttpService has millions of usages. You can use it to do things like create a web browser, or make a global leaderboard. (But maybe you should use OrderedDataStores for that, since that's easier and doesn't need HttpService) Once you have a webserver set up, you can use HttpService to connect to webpages on it. An example of this would be RoCRAFTERO web API. You can connect to those webpages using HttpService, and find lots of cool stuff!

The following is a made-up example of using HTTP Service to post a Lua Table to http://example.org/json-table

myTable = {}

myTable["exp"] = 1100

myTable["gold"] = 999

myTable["swordID"] = 1000398

-- Initialize an HTTP Service pointer

hs = game:GetService("HttpService")

-- Encodes the Table into a JSON string.

myTableJSON = hs:JSONEncode(myTable)

-- Posts the JSON string to http://example.org/json-table

hs:PostAsync("http://example.org/json-table", myTableJSON)

Retrieving the same table after it has been posted, and assuming that the previously mentioned URL Contained NOTHING ELSE BUT the JSON table.

-- Initialize an HTTP Service pointer

hs = game:GetService("HttpService")

-- Uses a GET Request to pull down whatever is on http://example.org/json-table, which in this example is simply the JSON table posted previously.

myTableJSON = hs:GetAsync("http://example.org/json-table", true)

-- Decodes the JSON String we just received into a Lua Table.

myTable = hs:JSONDecode(myTableJSON)

-- Returns myTable, which looks like {"exp"=1100, "gold"=999, "swordID" = 1000398}

Restrictions

  • HttpService cannot access Roblox domains.

  • You can only make 500 requests per minute. This is to stop players from clogging up the RoCRAFTERO servers.

  • You must have "http://" or "https://" at the beginning of your URL.

Common errors

HTTP requests are not enabled

Locate HttpService under the Explorer window, and find HttpEnabled under Properties. This has to be set to true (the box has to be checked) for HttpService to work.

Http requests can only be executed by game server

Http Requests can only be sent from a game server. These include:

  • Your game in play mode

  • Tools -> Test -> Start Server

Run your Script from there instead.

PLEASE NOTE: USE THIS URL FOR SAVING TABLES FOR TESTING DUE TO A JSON BUG:


 
 
 

Recent Posts

See All
Introducing our Animation Studio

We have good news about this! We just introduced our virtual, non physical, animation studio, where we created short movies or short...

 
 
 

Comments


© 2025 RoCRAFTERO. RoCRAFTERO is a non-registered trademark of RoCRAFTERO Corporation. - Formely "MINECRAFTERS CORPORATION"

"RoCRAFTERO" are not affilated with Roblox Corporation, or Mojang AB.

 

RoCRAFTERO is a unofficial community of Roblox, and Minecraft and more games

This site is created by the RoCRAFTERO Staff/Admin/Owners and the creator ELCRAFTEROSITOTUPROSITO (The real name of the creator of this site is Alain.)

bottom of page