# HTTP 요청 보내기

Lua 스크립트를 이용해 아래와 같이 Http 요청을 보낼 수 있습니다.

## GET 요청 보내기

Server.HttpGet(url, callback)

예제)

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

```lua
-- http://naver.com URL로 GET 요청 보내고, res로 데이터 받기
Server.HttpGet('http://naver.com', function(res)
  print(res) -- 웹페이지가 반환한 결과 텍스트가 출력됩니다.
end)
```

{% endcode %}

## POST 요청 보내기

Server.HttpPost(url, data, callback)\
\
예제)

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

```lua
-- t 라는 테이블을 만들고, 보낼 POST 요청 데이터 넣기
t = {}
t.id = 1234
t.name = "Hello"

-- http://naver.com URL로 요청 보내고, res로 데이터 받기
Server.HttpGet('http://naver.com', t, function(res)
  print(res) -- 웹페이지가 반환한 결과 텍스트가 출력됩니다.
end)
```

{% endcode %}

## 웹 서버에서 데이터 받기

POST로 요청을 받을 경우, 아래와 같이 데이터를 출력할 수 있습니다.

이 데이터를 MySQL과 같은 데이터베이스에 넣어, 영구보관할 수 있습니다.

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

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

echo "잘 받았습니다!";
?>
```

{% endcode %}

`Server.HttpGet` 에서 보낸 데이터가 웹 서버에 잘 도착하였는지를 확인하기 위한 코드입니다.

위 서버 스크립트 예재의 `print(res)` 에 의해 “1234Hello잘 받았습니다!” 가 출력됩니다.


---

# 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/punkland-studio/effective-punkland/http.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.
