Send HTTP Request
You can send an HTTP request if you use the Lua script as shown below.
Send GET request
Server.HttpGet(url, callback)
Example:
1
2
3
4
-- http://google.com Send a GET request to the URL, and receive the data as res
Server.HttpGet('http://google.com', function(res)
print(res) -- The text printed by the web page is displayed.
end)
Send POST request
Server.HttpPost(url, data, callback)
Example:
1
2
3
4
5
6
7
8
9
-- t Create a table called t and then insert POST request data to send
t = {}
t.id = 1234
t.name = "Hello"
-- http://google.com Send a GET request to the URL, and receive the data as res
Server.HttpGet('http://google.com', t, function(res)
print(res) -- The text printed by web page is displayed.
end)
Receiving data from web server
If you receive a POST request, you can display the data as shown below.
You can put this data in a database like MySQL and keep it permanently.
1
2
3
4
5
6
<?php
echo $_POST["id"];
echo $_POST["name"];
echo "I've got it!";
?>
This is code to confirm that data sent from Server.HttpGet
to a web server arrived.