# 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!"`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.punkland.io/punkland-studio/effective-punkland/http-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
