Difference between revisions of "Http.get"

From ComputerCraft Wiki
Jump to: navigation, search
(Created page with "{{lowercase}} {{Function |name=http.get |args=string url |api=http |returns=table a file handle o...")
 
 
(11 intermediate revisions by 7 users not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=http.get
 
|name=http.get
|args=[[string (type)|string]] url
+
|args={{type|string}} url [, {{type|table}} headers]
|api=http
+
|api=HTTP
|returns=[[table (type)|table]] a [[Fs.open#Files_opened_in_text_read_mode|file handle]] of a readonly file containing the data returned from the specified url.
+
|returns={{type|table}} a [[HTTP (API)#Handles|handle]] on success, or [[nil]] on failure
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Attempts to download the file and blocks until the "http_success" or "http_failure" events have been fired.
+
|desc=Sends a HTTP GET request to a website, synchronously. Returns when the request completes, successfully or not.
 +
|examples=
 +
{{Example
 +
|desc=Gets the content of example.com (in HTML)
 +
|code=local sExample = http.get("http://example.com/") --Get contents of page<br />write(sExample.readAll()) --Read and print contents of page<br />sExample.close() --Just in case
 +
|output=The source of http://example.com/
 
}}
 
}}
 +
}}
 +
 +
[[Category:Lua_Core_Functions]]

Latest revision as of 19:54, 20 April 2014


Grid Redstone.png  Function http.get
Sends a HTTP GET request to a website, synchronously. Returns when the request completes, successfully or not.
Syntax http.get(string url [, table headers])
Returns table a handle on success, or nil on failure
Part of ComputerCraft
API HTTP

Examples

Grid paper.png  Example
Gets the content of example.com (in HTML)
Code
local sExample = http.get("http://example.com/") --Get contents of page
write(sExample.readAll()) --Read and print contents of page
sExample.close() --Just in case
Output The source of http://example.com/