Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http.request('http://www.timeapi.org/pst/now?\c')
- local function getHttpBody()
- http.request('http://www.timeapi.org/pst/now?\c')
- while true do
- local event, url, hBody = os.pullEvent()
- if event == "http_success" then
- print( "HTTP SUCCESS\nURL = "..url )
- return hBody
- elseif event == "http_failure" then
- error( "HTTP FAILURE\nURL = "..url ) -- If the error is not catched, this will exit the program.
- return nil -- In case this function is called via pcall.
- end
- end
- end
- local function processHttpBody( hBody, filename )
- local hFile
- if hBody then
- local body = hBody.readAll() -- Read the whole body.
- hFile = io.open( filename, "w" ) -- Open the provided filename for writing.
- hFile:write( body ) -- Write the body to the file.
- hFile:close() -- Save the changes and close the file.
- else
- print( "Sorry, no body to process." )
- end
- hBody.close() -- Do not know for sure if this is really necessary, but just in case.
- end
- processHttpBody(getHttpBody(),'swag')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement