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

Help: PostAsync help?

Asked by 8 years ago

I do not understand how I would change the data of a site, Example: Pastebin.

game:GetService("HttpService"):PostAsync("RAWDATA", string)

I do not understand what should happen?

0
If you don't understand HTTP, HttpService isn't going to be very valuable to you BlueTaslem 18071 — 8y
0
I do somewhat. Roblox_v10 33 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago

HttpService is used for communicating data to a different server that is NOT hosted by roblox.

A server is just a computer that is connected to the internet that is used to do something.

:PostAsync and :GetAsync are both used for communicating data to remote servers. (Remote meaning that it is a server that is not hosted by roblox.) (To host something basically means to run or own a server.)

HttpService is all about URLs.

Lets look at an example URL.

Say we have the URL "http://www.example.com/useful_script_that_processes_stuff.php?argument1=value1&argument2=value2"

Let's break this URL down.

The first part, http://indicates that we are using HTTP (hyper-text transfer protocol) to transfer data between the roblox game and another server. This tells the computer how to send data. The second part www.example.com/index.php is a reference to a file on the remote server that our roblox game will be talking to. Everything after the ? is called a GET parameter. Think of the GET parameters like variables in a roblox script. All that it's saying is that:

argument1 = "value1"

AND

argument2 = "value2"

These "variables" contain the data that we are communicating to the remote server.

Once the variables are sent to the remote server, the remote server has to process the data. This is usually done using some other server-sided scripting language such as PHP. If you would like to learn to use PHP, please read some other tutorials off of SH. I don't think that SH can help you much here.

Once the remote server has processed the data, it sends a response back to the roblox game. You can put this response into a variable in your script to use it to your advantage.

The :GetAsync() method requires only one argument: HttpService:GetAsync(String url)

In the method, the url parameter is what you use to pass data to the remote server. The GET parameters will be passed along to the remote server.

Let's take a look at an example use of the :GetAsync() method.

httpService = game:GetService("HttpService");
response = httpService:GetAsync("http://www.example.com/my_remote_server_script.php?parameter1=argument1&parameter2=argument2");

In this example, the PHP file on the remote server named "my_remote_server_script.php" will receive the "variables":

parameter1 = "argument1"

AND

parameter2 = "argument2"

The remote PHP file will do what it wants with the "variables", and send back a response to your roblox game.

The response will be a plain string. If you use the :GetAsync() method on a page that is supposed to be displayed in a web browser such as firefox, you might see HTML tags. For more information on HTML, please visit another website.

Now that you understand :GetAsync(), you can understand :PostAsync(). You can think of PostAsync as the same thing as :GetAsync(), except in PostAsync, the variables are NOT passed to the remote server in the URL. Instead, the variables are passed in the second parameter in the :PostAsync() method.

PostAsync behaves virtually the same way as GetAsync, except that it is a lot better since there is a special way that you can send lua tables to the remote server using PostAsync. This is done using JSON, however that's another tutorial.

That about concludes my BASIC tutorial on roblox's HttpService. If you need any further help, you should check out the wiki, as coverage on this topic is pretty thorough, or you can ask another friendly SH.

Anyways, hope you learned something.

Ad

Answer this question