Difference between revisions of "Http failure (event)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created event page)
 
(Trim a bit, clarify description)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{NeedsWork|A demonstration on the use and handling of this event would be beneficial. ''[[User:AfterLifeLochie|AfterLifeLochie]] 15:53, 30 November 2012 (MSK)''}}
 
 
 
{{Event
 
{{Event
 
|name=http_failure
 
|name=http_failure
|desc=Fired when a call to [[http.request|http.request()]], [[http.get|http.get()]] or [[http.post|http.post()]] fails.
+
|return1=The URL to the website
|return1=The URL to the website.
+
|desc=Fired when a call to [[http.request]] fails, and used internally in [[http.get]] and [[http.post]].
 +
}}
 +
{{Example
 +
|desc=Prints a message and quits when the requested URL could not be contacted.
 +
|code=
 +
http.request( "http://www.example-failure.com" )
 +
while true do
 +
  event, url = os.pullEvent()
 +
  if event == "http_failure" then
 +
    print( "Cannot contact the server: "..url )
 +
    break
 +
  end
 +
end
 
}}
 
}}

Latest revision as of 23:05, 5 May 2013



Grid Modem.png  Event http_failure
Fired when a call to http.request fails, and used internally in http.get and http.post.
Returned Object 1 The URL to the website


Grid paper.png  Example
Prints a message and quits when the requested URL could not be contacted.
Code
http.request( "http://www.example-failure.com" )
while true do
  event, url = os.pullEvent()
  if event == "http_failure" then
    print( "Cannot contact the server: "..url )
    break
  end
end