http - http Client#

Adapted Air780E/Air700E Air780EP Air601 Air101/Air103 Air105 ESP32C3 ESP32S3


This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!


This library has its own demo,click this link to view http demo examples


-- To use the http library, you need to introduce the sysplus library and use it in the task.
require "sys"
require "sysplus"

    local code,headers,body = http.request("GET", "").wait()"http", code, body)

http.request(method,url,headers,body,opts,ca_file,client_ca, client_key, client_password)#

http Client


Incoming Value Type



The request method, which supports legitimate HTTP methods such as GET and POST.


url Address, support http and https, support domain name, support custom port


The request header is optional such {[“Content-Type”] = “application/x-www-form-urlencoded”}


body Optional


Additional configuration options include timeout: timeout unit ms is optional, default is 10 minutes, write 0 is permanent wait dst: download path, optional adapter: select to use network card, optional debug: whether to open debug information, optional, ipv6: whether to ipv6 default is not, optional callback: download callback function, parameter content_len: total length body_len: userdata user parameter by download length, optional userdata: callback custom parameter


server ca certificate data, optional, generally not required


client ca certificate data, optional, generally not required, two-way https authentication is required


client private key encryption data, optional, generally not required, two-way https authentication is required


Client private key password data, optional, generally not required, two-way https authentication is required.

Return Value

return value type



code , The value of server feedback is> = 100, the most common is 200. If it is a low-level error, such as connection failure, the return value is less 0


headers When 100, the header data returned on behalf of the server


body The content string of the server response, or the file size if it is in download mode


code Error reporting information list:
-1 HTTP_ERROR_STATE Error status, usually a bottom-level exception, please report issue
-2 HTTP_ERROR_HEADER Incorrect response header, usually a server problem
-3 HTTP_ERROR_BODY Bad response body, usually a server problem
-4 HTTP_ERROR_CONNECT Failed to connect to server, not networked, address error, domain name error
-5 HTTP_ERROR_CLOSE Disconnected prematurely, network or server issues
-6 HTTP_ERROR_RX Receive data error, network problem
-7 HTTP_ERROR_DOWNLOAD Error reported during file download, network problem or download path problem
-8 HTTP_ERROR_TIMEOUT Timeouts, including connection timeouts, read data timeouts
-9 HTTP_ERROR_FOTA fota The function reports an error, usually because the update package is illegal.

-- GET Request
local code, headers, body = http.request("GET","").wait()"http.get", code, headers, body)
-- POST Request
local code, headers, body = http.request("POST","", {}, "abc=123").wait()"", code, headers, body)

-- GET request, but download to file
local code, headers, body = http.request("GET","", {}, "", {dst="/data.bin"}).wait()"http.get", code, headers, body)

-- Custom Timeout, 5000ms
http.request("GET","", nil, nil, {timeout=5000}).wait()