You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
client() - returns http client instance for further usage. Avaliable options as table:
proxy="http(s)://<user>:<password>@host:<port>",
timeout= 10,
insecure_ssl=false,
user_agent = "gopher-lua",
basic_auth_user = "",
basic_auth_password = "",
headers = {"key"="value"},
debug = false,
# When set, the client will present the client cert for "mTLS"
client_public_cert_pem_file = nil,
client_private_key_pem_file = nil,
# When set, this will be used to verify the server certificate (useful for private enterprise certificate authorities).
# Prefer this over insecure_ssl when possible
root_cas_pem_file = "",
request(method, url, [data]) - make request userdata.
Methods
client
do_request(request) - returns result of request. Avaliable data are: 'body', 'headers', 'code'
Examples
Client
localhttp=require("http")
localclient=http.client()
-- GETlocalrequest=http.request("GET", "http://hostname.com")
localresult, err=client:do_request(request)
iferrthenerror(err)
endifnot (result.code==200) thenerror("code")
endifnot (result.body=="xxx.xxx.xxx.xxx") thenerror("body")
end-- auth basiclocalrequest=http.request("GET", "http://hostname.com")
request:set_basic_auth("admin", "123456")
-- headerslocalclient=http.client()
localrequest=http.request("POST", "http://hostname.com/api.json", "{}")
request:header_set("Content-Type", "application/json")
-- with proxylocalclient=http.client({ proxy="http(s)://login:[email protected]" })
localrequest=http.request("POST", "http://hostname.com/api.json", "{}")
-- ignore ssllocalclient=http.client({ insecure_ssl=true })
localrequest=http.request("POST", "http://hostname.com/api.json", "{}")
-- set headers for all requestlocalclient=http.client({ headers= { key="value" } })
-- set basic auth for all requestlocalclient=http.client({ basic_auth_user="admin", basic_auth_password="123456" })
localserver, err=http.server("127.0.0.1:1113")
iferrthenerror(err)
endserver:do_handle_string([[ -- do_handle_file-- same methods for request like in accept -- get bodylocal body, err = request.body()if err then error(err) endprint("body:", body)response:code(200) -- write headerresponse:write(request.request_uri)response:done()]]