Difference between revisions of "Http.request"

From ComputerCraft Wiki
Jump to: navigation, search
(Add function layout + information)
(Fixed example -- http://www.computercraft.info/forums2/index.php?/topic/3467-)
Line 14: Line 14:
 
     local event, url, sourceText = os.pullEvent()<br />
 
     local event, url, sourceText = os.pullEvent()<br />
 
     if event == "http_success" then<br />
 
     if event == "http_success" then<br />
       respondedText = code.readAll()<br />
+
       respondedText = sourceText.readAll()<br />
 
       print(respondedText)<br />
 
       print(respondedText)<br />
 
       requesting = false<br />
 
       requesting = false<br />

Revision as of 03:31, 17 September 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")
requesting = true
while requesting do
local event, url, sourceText = os.pullEvent()
if event == "http_success" then
respondedText = sourceText.readAll()
print(respondedText)
requesting = false
else
print("Server didn't respond.")
requesting = false
end end