Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with GetAsync for HttpsServices?

Asked by
Txeer 46
5 years ago

I am kind of confused on how to call on a link with GetAsync, any help?

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago
Edited 5 years ago

Assuming Allow HTTP Requests is set to "On", or set to "True" in your script...

--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.

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’confirm. This is what HttpService:PostAsync does. When you call HttpService: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)

HttpService cannot access Roblox domains. You can only make 500 requests per minute. This is to stop players from clogging up the Roblox servers. You must have “http://” or “https://” at the beginning of your URL.

HttpService can also send strings (tables) to websites... From Dev - -

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}

Link to JSON wiki... http://robloxdev.com/articles/JSON-Storage-Format

Ad

Answer this question