Difference between revisions of "HTTP (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Changed from mod_ComputerCraft.cfg to ComputerCraft.cfg)
m (Added types)
Line 13: Line 13:
 
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
 
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.request]]( url, *postData )</td>
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.request]]( {{type|string}} url, {{type|string}} *postData )</td>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP request to a website.</td></tr>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP request to a website.</td></tr>
  
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.get]]( url )</td>
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.get]]( {{type|string}} url )</td>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP GET request to a website.</td></tr>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP GET request to a website.</td></tr>
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.post]]( url, postData )</td>
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[http.post]]( {{type|string}} url, {{type|string}} postData )</td>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP POST request to a website.</td></tr>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sends a HTTP POST request to a website.</td></tr>
 
</table>
 
</table>

Revision as of 14:07, 3 May 2013

The HTTP API must be enabled in mod_ComputerCraft.cfg before being used. To enable it open .minecraft/config/ComputerCraft.cfg and change enableAPI_http=false to enableAPI_http=true.

The HTTP API allows interfacing with websites and downloading from them.

Grid disk.png   HTTP (API)

Method NameDescription
http.request( string url, string *postData ) Sends a HTTP request to a website.
http.get( string url ) Sends a HTTP GET request to a website.
http.post( string url, string postData ) Sends a HTTP POST request to a website.

A period of time after a http.request() call is made, a "http_success" or "http_failure" event will be raised to os.pullEvent(). Arguments are the URL and a file handle if successful. http.get() blocks until this event is fired.