Difference between revisions of "Http.request"

From ComputerCraft Wiki
Jump to: navigation, search
(Fixed example -- http://www.computercraft.info/forums2/index.php?/topic/3467-)
(Add local variables)
Line 10: Line 10:
 
|desc=Prints the code of a loading bar program if successful.
 
|desc=Prints the code of a loading bar program if successful.
 
|code=http.request("http://pastebin.com/raw.php?i=Tk19jv43")<br />
 
|code=http.request("http://pastebin.com/raw.php?i=Tk19jv43")<br />
   requesting = true<br />
+
   local requesting = true<br />
 
   while requesting do<br />
 
   while requesting do<br />
 
     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 = sourceText.readAll()<br />
+
       local respondedText = sourceText.readAll()<br />
 
       print(respondedText)<br />
 
       print(respondedText)<br />
 
       requesting = false<br />
 
       requesting = false<br />

Revision as of 03:32, 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")
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
else
print("Server didn't respond.")
requesting = false
end end