local Network = require("network")
local net = Network.new("MyLuaAgent/1.0", 15000) -- user agent and timeout in ms
-- Simple HTTP GET
local body, err = net:http_get("https://httpbin.org/get")
print(body or "Error: " .. err)
-- Get headers
local headers = net:http_headers("https://httpbin.org/get")
print(headers)
-- Download file
local ok, err = net:download("test.txt", "https://example.com/file.txt")
print(ok and "Download successful!" or ("Failed: " .. err))
-- Download with progress
net:download_with_progress("image.jpg", "https://example.com/image.jpg", function(dl, total)
print(("Progress: %.2f%%"):format((dl / (total > 0 and total or 1)) * 100))
end)
-- Cancel ongoing download (call from another coroutine/thread/timer)
net:cancel_download()
local net = Network.new("MyLuaAgent/1.0", 15000) -- user agent and timeout in ms
-- Simple HTTP GET
local body, err = net:http_get("https://httpbin.org/get")
print(body or "Error: " .. err)
-- Get headers
local headers = net:http_headers("https://httpbin.org/get")
print(headers)
-- Download file
local ok, err = net:download("test.txt", "https://example.com/file.txt")
print(ok and "Download successful!" or ("Failed: " .. err))
-- Download with progress
net:download_with_progress("image.jpg", "https://example.com/image.jpg", function(dl, total)
print(("Progress: %.2f%%"):format((dl / (total > 0 and total or 1)) * 100))
end)
-- Cancel ongoing download (call from another coroutine/thread/timer)
net:cancel_download()