Makes an HTTP request.
request(options: table) -> table
local response = request({
Url = "https://httpbin.org/get",
Method = "GET"
})
if response.Success then
print("Status:", response.StatusCode)
print("Body:", response.Body)
end
local HttpService = game:GetService("HttpService")
local response = request({
Url = "https://httpbin.org/post",
Method = "POST",
Headers = {
["Content-Type"] = "application/json"
},
Body = HttpService:JSONEncode({
username = "player",
score = 100
})
})
if response.Success then
local data = HttpService:JSONDecode(response.Body)
print(data)
end
local success, response = pcall(request, {
Url = "https://example.com/api",
Method = "GET"
})
if success and response.Success then
print("Got data:", response.Body)
elseif success then
warn("HTTP Error:", response.StatusCode, response.StatusMessage)
else
warn("Request failed:", response)
end