http_failure event

From ComputerCraft
Jump to: navigation, search
http_failure
Event
Returns
  • url : string The URL of the request
  • reason : string The reason the request failed. Most often "Could not connect."
  • stream? : table A file handle-like object. If the connection failed, this will not be returned.

Source CC:Tweaked

Fired when a request created with http.request fails.

ExampleExampleRequest a page
Requests the example 404 page and prints the result.
Code
-- Request the example page
http.request("https://example.computercraft.cc/404")
while true do
  -- Wait for a http_failure event.
  local event, url, handle = os.pullEvent("http_failure")
  -- If it's for our URL, then print the result.
  if url == "https://example.computercraft.cc/404" then
    print(reason, handle and handle.readAll() or "")
    if handle then handle.close() end
  end
end