The HTTP API provides access to basic HTTP functionality. Depending on how TPT is built, it may only work with secure sites (ones that use TLS, i.e. HTTPS) or it may not even be available.
assert(http, "HTTP functionality unavailable")
Returns one of the following:
- "running" if the request hasn't finished yet;
- "done" if the request has finished and the response body is ready to be read;
- "dead" if the request is dead, i.e. if it has been cancelled or if the response body has been read.
number, number HTTPRequest:progress()
If the request is not dead, returns the size of the response body in bytes in the first return value (-1 if the size is not known), and the number of bytes received so far in the second. If the request is dead, returns nothing.
Cancels the request. Does nothing if the request is dead.
string, number HTTPRequest:finish()
Finishes the request and returns the response body and the status code. Call this only when HTTPRequest:status returns "done". Does and returns nothing if the request is dead.
HTTPRequest http.request(string uri, [table post_params, [table headers]])
Constructs a HTTPRequest object and starts the underlying request immediately with the URI, post parameters and headers supplied. Both optional tables are collections of string key and string value pairs. The request is a POST if post parameters are supplied, a GET otherwise.