Advertisement
Applepirate

anothertest

Aug 21st, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. http.request('http://www.timeapi.org/pst/now?\c')
  2. local function getHttpBody()
  3. http.request('http://www.timeapi.org/pst/now?\c')
  4.  
  5. while true do
  6. local event, url, hBody = os.pullEvent()
  7. if event == "http_success" then
  8. print( "HTTP SUCCESS\nURL = "..url )
  9. return hBody
  10. elseif event == "http_failure" then
  11. error( "HTTP FAILURE\nURL = "..url ) -- If the error is not catched, this will exit the program.
  12. return nil -- In case this function is called via pcall.
  13. end
  14. end
  15. end
  16.  
  17. local function processHttpBody( hBody, filename )
  18. local hFile
  19.  
  20. if hBody then
  21. local body = hBody.readAll() -- Read the whole body.
  22. hFile = io.open( filename, "w" ) -- Open the provided filename for writing.
  23. hFile:write( body ) -- Write the body to the file.
  24. hFile:close() -- Save the changes and close the file.
  25. else
  26. print( "Sorry, no body to process." )
  27. end
  28.  
  29. hBody.close() -- Do not know for sure if this is really necessary, but just in case.
  30. end
  31.  
  32.  
  33. processHttpBody(getHttpBody(),'swag')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement