Difference between revisions of "Http success (event)"
From ComputerCraft Wiki
(Created event page for http_success) |
(Trim a bit, clarify description, point back at the handle description in HTTP API) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
{{Event | {{Event | ||
|name=http_success | |name=http_success | ||
− | |desc=Fired when a call to [[http.request | + | |desc=Fired when a call to [[http.request]] completes successfully, and used internally in [[http.get]] and [[http.post]]. |
− | |return1=The URL to the website | + | |return1=The URL to the website |
− | |return2=A | + | |return2=A [[HTTP (API)#Handles|handle]] that allows reading the response sent from the server |
+ | }} | ||
+ | {{Example | ||
+ | |desc=Prints the response code from the server and the text returned from the server | ||
+ | |code= | ||
+ | http.request( "http://www.example.com" ) | ||
+ | event, url, handle = os.pullEvent( "http_success" ) | ||
+ | print( "Got a response with the status code: "..handle.getResponseCode() ) | ||
+ | print( "With the text: "..handle.readAll() ) | ||
+ | handle:close() | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Prints all the available functions to call on the response from the server | ||
+ | |code= | ||
+ | http.request( "http://www.example.com" ) | ||
+ | while true do | ||
+ | event, url, handle = os.pullEvent( "http_success" ) | ||
+ | for k, v in pairs( handle ) do | ||
+ | print( k ) | ||
+ | end | ||
+ | end | ||
}} | }} |
Latest revision as of 23:03, 5 May 2013
![]() | |
Fired when a call to http.request completes successfully, and used internally in http.get and http.post. | |
Returned Object 1 | The URL to the website |
Returned Object 2 | A handle that allows reading the response sent from the server |
![]() | |
Prints the response code from the server and the text returned from the server | |
Code |
http.request( "http://www.example.com" ) event, url, handle = os.pullEvent( "http_success" ) print( "Got a response with the status code: "..handle.getResponseCode() ) print( "With the text: "..handle.readAll() ) handle:close() |
![]() | |
Prints all the available functions to call on the response from the server | |
Code |
http.request( "http://www.example.com" ) while true do event, url, handle = os.pullEvent( "http_success" ) for k, v in pairs( handle ) do print( k ) end end |