HttpClient
Use the following methods to add URL references to your Lua script. Transfer data over a secure HTTP connection, or encode and decode a URL, parameters, and string data into a valid ASCII format without spaces.

Specify a URL from which to download data.
Syntax
HttpClient.Download( table )
Arguments
table : A comma-separated list of parameters:
Url = string : The URL to download from.
Headers = table : A table of headers, (string --> string)
User = string : Username for authenticated sites.
Password = string : Password for authenticated sites.
Timeout = number : The timeout, in seconds, for the HttpClient call.
EventHandler = function : EventHandler to call with status. Signature is function( table, code, data, error, headers ). 'code' is the http return code (200 is good).
Example
Get a web page and show the return code, the page source, and any errors in the debug window after a 30 second timeout.
function done(tbl, code, data, err, headers) print(string.format( "HTTP response from '%s': Return Code=%i; Error=%s", tbl.Url, code, err or "None" ) ) print("Headers:") for hName,Val in pairs(headers) do print(string.format( "\t%s = %s", hName, Val ) ) end print( "\rHTML Data: "..data ) end HttpClient.Download { Url = "http://www.google.com", Headers = { ["Content-Type"] = "application/json" } , Timeout = 30, EventHandler = done }

Specify a URL to which to upload data.
Syntax
HttpClient.Upload( table )
Arguments
table : A comma-separated list of parameters:
Url = string : The URL to upload to.
Headers = table : A table of headers, (string --> string)
User = string : Username for authenticated sites.
Password = string : Password for authenticated sites.
Data = string : Data string to upload.
Method = POST | PUT : The method for uploading.
Timeout = number : The timeout, in seconds, for the HttpClient call.
EventHandler = function : EventHandler to call with status. Signature is function( table, code, data, error, headers ). 'code' is the http return code (200 is good).
Example
Send Post data to a web site (Henry's Post Test Server V2).
URL = Controls.URL post = Controls.Post TestID = Controls.TestID function done(tbl, code, d, e) print( string.format("Response Code: %i\t\tErrors: %s\rData: %s",code, e or "None", d)) end function Upload() local BaseURL = string.format("https://ptsv2.com/t/%s",TestID.String) print(string.format("Go to "..BaseURL.." to view the dump information")) HttpClient.Upload { Url = BaseURL.."/post", Method = "POST", -- Can be either POST or PUT. The Post Test Server v2 doesn't use PUT. User = "user123", -- Used only for Basic or Digest Authentication Password = "mypassword", -- Used only for Basic or Digest Authentication Data = "this is a test", -- This can be anything Headers = { ["Content-Type"] = "text/html", Larry = "another larry", Authentication = "If it is here, it isn't Basic or Digest authentication" }, EventHandler = done -- The function to call upon response } end post.EventHandler = Upload

Combine URL components into a complete encoded URL string.
Syntax
HttpClient.CreateUrl( table )
Arguments
table : A comma-separated list of parameters containing, at minimum, a URL name. Optionally specify a port, path, and query. See the example for proper syntax.
Host = "url_name"
Port = url_port
Path = "url_path"
Query = "url_query"
Example
print( HttpClient.CreateUrl( { Host = "http://www.go.com" } )) => http://www.go.com print( HttpClient.CreateUrl( { Host = "http://www.go.com", Port = 1234 } )) => http://www.go.com:1234 print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path" } )) => http://www.go.com:1234/this/is/a/path print( HttpClient.CreateUrl( { Host = "http://www.go.com", Port = 1234, Path = "this/is/a/path" } )) => http://www.go.com:1234/this/is/a/path print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path with space" } )) => http://www.go.com/this/is/a/path%20with%20space print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path with space", Query = { sky = "blue" }})) => http://www.go.com/this/is/a/path%20with%20space?sky=blue print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path with space", Query = { sky = "blue", term = "hellothere" }})) => http://www.go.com/this/is/a/path%20with%20space?sky=blue&term=hellothere print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path with space", Query = { sky = "blue", term = "hello | there" }})) => http://www.go.com/this/is/a/path%20with%20space?sky=blue&term=hello%20%7c%20there print( HttpClient.CreateUrl( { Host = "http://www.go.com", Path = "this/is/a/path with space", Query = { ["name with space"] = "blue", term = "hello | there" }})) => http://www.go.com/this/is/a/path%20with%20space?term=hello%20%7c%20there&name%20with%20space=blue

Specify a comma-separated list of parameters to encode.
Syntax
HttpClient.EncodeParams( table )
Arguments
table : A comma-separated list of parameters to encode. See the example for proper syntax.
Example
print( HttpClient.EncodeParams( { ["name with space"] = "blue", term = "hello | there" })) => term=hello%20%7c%20there&name%20with%20space=blue

Specify a string to encode.
Syntax
HttpClient.EncodeString( string )
Arguments
string : The string to encode.
Example
print( HttpClient.EncodeString( "this is | some test")) => this%20is%20%7c%20some%20test

Specify an encoded string to decode.
Syntax
HttpClient.DecodeString( string )
Arguments
string : The encoded string to decode.
Example
print( HttpClient.DecodeString("this%20is%20%7c%20some%20test")) => this is | some test