http - Робота з HTTP запитами

Функції для виконання HTTP запитів.

Приклад:

 1-- збереження результату в файл
 2local request = {
 3    url = "https://a.tile.openstreetmap.org/12/2395/1381.png",
 4    file = "/12/2395/1381.png"
 5}
 6local response = http.execute(request)
 7console.print("Result:", response.code)
 8
 9-- повернення результату у вигляді рядка
10request = {
11    url = "https://api.appstoreconnect.apple.com/v1/devices"
12}
13local response = http.execute(request)
14console.print(response.code, response.response)
class http
static execute(options)

Виконує HTTP-запит з параметрами, вказаними у таблиці.

Очікує таблицю з такими ключами: url (string): URL для запиту. method (string, необов’язково): HTTP-метод (GET, POST тощо). За замовчуванням: «GET», якщо немає тіла запиту. «POST», якщо тіло запиту вказано. body (string, необов’язково): Тіло запиту (для POST або інших методів). file (string, необов’язково): Ім’я файлу для збереження відповіді.

Повертає таблицю з результатом запиту: code (integer): HTTP-код відповіді. response (string, необов’язково): Відповідь сервера (тільки якщо file не задано).

Parameters:

options (table) – таблиця з параметрами запиту

Returns:

результат запиту

Return type:

table

Usage:

1local result = http.execute({
2    url = "https://example.com/api",
3    method = "GET",
4})
5print("HTTP Code:", result.code)
6if result.response then
7    print("Response:", result.response)
8end