Difference between revisions of "HTTP (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(There is no header_table version of the functions in ComputerCraft, This is not LuaSocket!)
Line 10: Line 10:
 
|-
 
|-
 
| [[http.request]]( url )<br />
 
| [[http.request]]( url )<br />
[[http.request]] { header_table }
 
 
|  
 
|  
 
|-
 
|-
Line 17: Line 16:
 
|-
 
|-
 
| [[http.post]]( url, data )<br />
 
| [[http.post]]( url, data )<br />
[[http.post]] { header_table }
 
 
|
 
|
 
|}
 
|}
Line 23: Line 21:
 
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.
 
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.
  
==header_table format==
 
(Source: http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-alpha/http.html )
 
Note the {} braces.
 
<pre>
 
http.get{
 
  url = string,
 
  headers = header-table,
 
  user = string,
 
  password = string,
 
  stay = bool,
 
}
 
http.post{
 
  url = string,
 
  headers = header-table,
 
  body = string,
 
  user = string,
 
  password = string,
 
  stay = bool,
 
}
 
http.request{
 
  method = string,
 
  url = string,
 
  headers = header-table,
 
  body = string,
 
  user = string,
 
  password = string,
 
  stay = string,
 
}
 
</pre>
 
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 08:51, 10 July 2012

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

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

Methods

Method name Description
http.request( url )
http.get( url )
http.post( url, data )

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.