mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
update doc/*/scripting/builtins/libnetwork.md
This commit is contained in:
parent
a773dfbd0e
commit
817092fef4
2 changed files with 67 additions and 1 deletions
|
|
@ -4,6 +4,39 @@ A library for working with the network.
|
||||||
|
|
||||||
## HTTP requests
|
## HTTP requests
|
||||||
|
|
||||||
|
There is a configurable function `network.request` that allows performing HTTP requests with various methods (GET, POST, PUT, DELETE, etc.) and configuring headers, request body, timeout, and other parameters.
|
||||||
|
|
||||||
|
>[!NOTE] To pass binary data in the request body, use a byte array (Bytearray) or a string. In `on_response`, the `body` string can be converted to a byte array using `Bytearray(response.body)`.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
network.request(
|
||||||
|
url: string,
|
||||||
|
parameters: {
|
||||||
|
-- Request method (GET, POST, PUT, DELETE, etc.)
|
||||||
|
method: string,
|
||||||
|
-- Request body as a string or Bytearray
|
||||||
|
body: table|string,
|
||||||
|
-- List of additional request headers
|
||||||
|
headers: table<string>,
|
||||||
|
-- Timeout in milliseconds
|
||||||
|
timeout: int,
|
||||||
|
-- Whether to verify the SSL certificate
|
||||||
|
verify_ssl: boolean,
|
||||||
|
-- Function called when a response is received
|
||||||
|
on_response: function(response: {
|
||||||
|
-- HTTP response status code
|
||||||
|
status: int,
|
||||||
|
-- Response body as a string
|
||||||
|
body: string,
|
||||||
|
-- List of response headers
|
||||||
|
headers: table<string>
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Simplified functions for GET and POST requests
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Performs a GET request to the specified URL.
|
-- Performs a GET request to the specified URL.
|
||||||
network.get(
|
network.get(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,39 @@
|
||||||
|
|
||||||
## HTTP-Запросы
|
## HTTP-Запросы
|
||||||
|
|
||||||
|
Существует настраиваемая функция `network.request`, которая позволяет выполнять HTTP-запросы с различными методами (GET, POST, PUT, DELETE и т.д.) и настраивать заголовки, тело запроса, таймаут и другие параметры.
|
||||||
|
|
||||||
|
>[!NOTE] Для передачи двоичных данных в теле запроса, используйте массив байт (Bytearray) или строку. В `on_response` строку `body` можно преобразовать в массив байт с помощью `Bytearray(response.body)`.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
network.request(
|
||||||
|
url: string,
|
||||||
|
parameters: {
|
||||||
|
-- Метод запроса (GET, POST, PUT, DELETE и т.д.)
|
||||||
|
method: string,
|
||||||
|
-- Тело запроса в виде строки или массива байт (Bytearray)
|
||||||
|
body: table|string,
|
||||||
|
-- Список дополнительных заголовков запроса
|
||||||
|
headers: table<string>,
|
||||||
|
-- Таймаут в миллисекундах
|
||||||
|
timeout: int,
|
||||||
|
-- Проверять ли SSL-сертификат
|
||||||
|
verify_ssl: boolean,
|
||||||
|
-- Функция, вызываемая при получении ответа
|
||||||
|
on_response: function(response: {
|
||||||
|
-- HTTP-код ответа
|
||||||
|
status: int,
|
||||||
|
-- Тело ответа в виде строки
|
||||||
|
body: string,
|
||||||
|
-- Список заголовков ответа
|
||||||
|
headers: table<string>
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Упрощённые функции для GET и POST запросов
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Выполняет GET запрос к указанному URL.
|
-- Выполняет GET запрос к указанному URL.
|
||||||
network.get(
|
network.get(
|
||||||
|
|
@ -231,4 +264,4 @@ network.get_total_download() -> int
|
||||||
```lua
|
```lua
|
||||||
-- Ищет свободный для использования порт.
|
-- Ищет свободный для использования порт.
|
||||||
network.find_free_port() -> int | nil
|
network.find_free_port() -> int | nil
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue