| Socket | A HTTP client socket. |
| const GET | The GET method string. |
| const HEAD | The HEAD method string. |
| const POST | The POST method string. |
| closeExpired() | Close and and remove any expired socket. |
| connect(url, ttl=240):abhttp.Socket | Get a connected socket by its URL, going through the connection cache. |
| encodeparams(params) | Encode an array of parameters. |
| parseUrl(url) | Parse a URL into host, port and path. |
| request(url, method, params=..., fields=...):abhttp.Socket | Send a request to an URL, and return its socket, going through the connection cache. |
"http:" and "https:".
["host":host,"port":port,"path":path].
Sample usage:
// get the airbit logo into a file s:abhttp.Socket=abhttp.Socket("www.airbit.ch", 80); s.request(abhttp.GET, "/media/14/logo.jpg"); if s.handleResponse()=200 then print "Date:",s.fields["Date"]; f=io.create("airbit.jpg"); b=s.readContent(1024); // just any buffer size while b#null do io.write(f, b); b=s.readContent(1024) end; io.close(f) end; s.close()The module also supports simple URL parsing and connection caching via abhttp.parseUrl and abhttp.connect, abhttp.request. The example above can thus be simplified to: