# HTTP Requests

Using Lua scripts, you can send HTTP requests as shown below.

## **Sending a GET Request**

Server.HttpGet(url, callback)

Example)

{% code overflow="wrap" lineNumbers="true" %}

```lua
-- Send a GET request to http://naver.com and receive data in res
Server.HttpGet('http://naver.com', function(res)
  print(res) -- Prints the returned text from the webpage
end)
```

{% endcode %}

## Sending a POST Request

Server.HttpPost(url, data, callback)\
\
Example)

{% code overflow="wrap" lineNumbers="true" %}

```lua
-- Create a table named t and insert the POST request data
t = {}
t.id = 1234
t.name = "Hello"

-- Send a request to http://naver.com and receive the data in res
Server.HttpGet('http://naver.com', t, function(res)
  print(res) -- The returned text from the webpage is printed.
end)
```

{% endcode %}

## Receiving Data on the Web Server

When receiving a request via POST, you can print the data as shown below. You can store this data in a database like MySQL for long-term preservation.

{% code overflow="wrap" lineNumbers="true" %}

```lua
<?php
echo $_POST["id"];
echo $_POST["name"];

echo "sucess!";
?>
```

{% endcode %}

This code is used to verify that the data sent by **Server.HttpGet** has successfully reached the web server. In the server script example above, the `print(res)` statement outputs `"1234Hellosuccess!"`.
