Difference between revisions of "HTTP (API)"
From ComputerCraft Wiki
(Document synchrony and asynchrony) |
(Added link to tutorial on how to enable the HTTP API) |
||
Line 1: | Line 1: | ||
:{|class="wikitable" | :{|class="wikitable" | ||
− | | '''The HTTP API must be enabled in mod_ComputerCraft.cfg before being used. To enable it | + | | '''The HTTP API must be enabled in mod_ComputerCraft.cfg before being used. To enable it see [http://www.computercraft.info/forums2/index.php?/topic/17533-how-to-enable-the-http-api/ this tutorial].''' |
|} | |} | ||
Revision as of 08:01, 26 March 2014
The HTTP API must be enabled in mod_ComputerCraft.cfg before being used. To enable it see this tutorial.
The HTTP API allows interfacing with websites and downloading from them.
Return | Method Name | Description |
nil | http.request(string url, [string postData]) | Sends a HTTP request to a website, asynchronously. |
table handle | http.get(string url) | Sends a HTTP GET request to a website, synchronously. |
table handle | http.post(string url, string postData) | Sends a HTTP POST request to a website, synchronously. |
http.request is used to send a HTTP request that completes asynchronously and generates an event (one of http_success or http_failure). http.get and http.post execute http.request and block until the operation completes.
Handles
All three operations make use of handles, tables that contain functions to read data returned from the HTTP server. These handles act the same as the I/O handles returned by fs.open in read-only text mode, implementing the close, readLine, and readAll methods. These handles also implement the following function:
Function h.getResponseCode | |
Returns the numerical HTTP response code sent by the server | |
Syntax | h.getResponseCode() |
Returns | number HTTP response code |
Part of | ComputerCraft |
API | HTTP |