Hi,
if i want to implement an app that reads data from a website, is the code in Corona SDK/Lua the same for all devices, Android, iOS and Windows?
I tried running the code below in the simulator and i got the error
Attempt to index global ‘http’ (a nil value)
Does anyone have a template/sample code that i could use to read data from a website? Can be just a simple html file.
Thanks!
ttee
display.setStatusBar(display.HiddenStatusBar)
local path = system.pathForFile( “question.txt”, system.CachesDirectory)
local myFile = io.open( path, “w” )
http.request{
url = “http://web.textfiles.com/computers/386.txt”, sink = ltn12.sink.file(myFile),
}
print(tostring(myFile))
local contents = “”
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
io.close( file )
print(contents)
else
print(“file not found”)
end