Difference between revisions of "HTTP (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(added alternate HTTP call methods)
Line 3: Line 3:
 
Methods provided by the HTTP API:
 
Methods provided by the HTTP API:
  
* http.request( url )
+
* http.request( url ) OR http.request { header_table }
 
* http.get( url )
 
* http.get( url )
* http.post(???)
+
* http.post( url, data ) OR http.post { header_table }
  
 
The HTTP API must be enabled in mod_ComputerCraft.cfg before being used.
 
The HTTP API must be enabled in mod_ComputerCraft.cfg before being used.
  
 
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 00:44, 25 April 2012

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

Methods provided by the HTTP API:

  • http.request( url ) OR http.request { header_table }
  • http.get( url )
  • http.post( url, data ) OR http.post { header_table }

The HTTP API must be enabled in mod_ComputerCraft.cfg before being used.

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.

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,
}