Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i use HTML Service ?

How do i use Html service lets say a player is in a game and i am on A website and i Post some live chat to the website ( I am using Discord ) how do i make the game read that live chat and respond to it ?

2 comments

0

It's almost never necessary to use this service.

0

Actually this service is one of the most useful service out there.

2 answers

HttpService*

HttpService is a way to send GET and POST requests to live servers. Tho you don't need to have background knowledge in web development, it would help a whole lot.

There are 4 functions -GenerateGUID -JSONDecode -JSONEncode -UrlEncode

There are 2 functions that yield -GetAsync -PostAsync

We are only going to be talking about the functions that yield.

A GET request is pretty much a request that get the content of a web server.

For instance, if you type this in the console.

print(game.HttpService:GetAsync("https://www.example.com")

It will return the HTML of that page.

But how do I send data over? Sending data using a GetAsync is quite easy actually. The data format is in a Key/Value format and is stored in the Url.

local Data = "http://www.example.com/?var1=666&var2=1337&var=test

Now I am using PHP as the backend web server language. To access that data just simple do

<?php
$var1 = $_GET['var1']
$var2 = $_GET['var2']
$var = $_GET['var']
?>

But what about PostAsync. PostAsync post data to a web server. I highly recommend using JSON as the format for sending data to a web server. To begin I make a table that contain data I want to send to the server.

local Table = {
	ID = 1337,
	Stuff = 666
}

Next I will encode the data into JSON format

local Table = {
	ID = 1337,
	Stuff = 666
}

local Json = game.HttpService:JSONEncode(Table)

Finally I will send the data to the web server.

local Table = {
	ID = 1337,
	Stuff = 666
}

local Json = game.HttpService:JSONEncode(Table)
game.HttpService:PostAsync("http://www.example.com,  Json)

But how do I access it?

Well, PHP have a built in function called "readfile" and you use a php stream type "'php://input'"

$table = json_decode(readfile("php://input"));
echo $table['ID']; 

That will print out 1337.

Feel free to vote up. :)

Anymore questions? Just comment.

Personally, I do not know much about HttpService, but I do know a few things about it. You can use :GetAsync(String url) to send a GET request to that url. I am not sure how you would go around getting live chat feedback from Discord, as I do not use it, but I wish you luck finding out!

1 comment

0

Xonae do you know any of These that you are skilled in and can help in such as Irc

This discussion is preserved as it was. New answers, comments, and votes are closed.