Difference between revisions of "Http.request"

From ComputerCraft Wiki
Jump to: navigation, search
(Add local variables)
(Changed the example, because otherwise it'll stop on any event, which will cause a keypress or redstone update to stop it.)
Line 17: Line 17:
 
       print(respondedText)<br />
 
       print(respondedText)<br />
 
       requesting = false<br />
 
       requesting = false<br />
     else<br />
+
     elseif event == "http_failure" then<br />
 
       print("Server didn't respond.")<br />
 
       print("Server didn't respond.")<br />
 
       requesting = false<br />
 
       requesting = false<br />

Revision as of 10:20, 24 October 2012


Grid Redstone.png  Function http.request
Sends a HTTP request to the website. Returns event "http_success" on success.
Syntax http.request()
Returns event "http_success" on success.
Part of ComputerCraft
API http

Examples

Grid paper.png  Example
Prints the code of a loading bar program if successful.
Code
http.request("http://pastebin.com/raw.php?i=Tk19jv43")
local requesting = true
while requesting do
local event, url, sourceText = os.pullEvent()
if event == "http_success" then
local respondedText = sourceText.readAll()
print(respondedText)
requesting = false
elseif event == "http_failure" then
print("Server didn't respond.")
requesting = false
end end