url
This module provides URL and HTTP request functions. This module uses beautiful library libcurl as its backend
import url
' Simple HTTP GET
response = url.get("https://example.com/")
if response.code == 200
writeln(response.body) ' Success
elseif response.code != 0
writeln("Error: HTTP " & response.code) ' HTTP error
else
writeln(response.error_string) ' Connection or other error
endif
' HTTP GET with headers and params
headers = {
"Authorization": "Basic QWxhZGRpbjpPcGVuU2VzYW1l",
"User-Agent": "myapp/1.0.0"
}
params = {
"id": "A0110",
"name": "Sarah Zaira"
}
response = url.get("https://faruq.id/misc/get.php", params, headers)
if response.code == http.ok
writeln(response.body)
elseif response.code != 0
writeln("Error: HTTP " & response.code)
else
writeln(response.error_string)
endif
' Upload files using multipart form data
params = {
"id": "U1234",
"file1": file_data("data.txt"), ' Upload a file
"file2": file_data("some.zip") ' Upload another file
}
response = url.post("https://faruq.id/misc/post.php", params, true)
if response.code == 200
writeln("Upload complete!")
else
writeln(response.error_string)
endif
' Simple example how to download a file
response = url.get("https://dinfio.org/releases/files/3.1.03/dinfio-3.1.03-macos.pkg", "", {}, "file.pkg")
if response.code == 200
writeln("Download complete!")
else
writeln(response.error_string)
endif
http
— The default instance of class http
and provides common HTTP status codesurl
— The default instance of class url
bytes_unit()
— Get formatted bytes unit
file_data
— This class provides MIME file data
construct()
— The constructor. Create an instance of class file_data
and create MIME file data http
— This class provides common HTTP status codes
response
— This class stores HTTP response from function url.get()
and url.post()
url
— Main class that implements HTTP GET request, HTTP POST request, etc
decode()
— Convert an encoded URL string to plain string encode()
— Convert a string to URL encoded string follow_location()
— Global configuration: set the HTTP 3xx follow redirects on or off get()
— Perform HTTP GET request post()
— Perform HTTP POST request proxy()
— Global configuration: set the proxy to use ssl_cainfo()
— Global configuration: set the path to Certificate Authority (CA) bundle