I am stuck when trying to use wax.http to download a file (in this
case it's a .doc file); here's the code:
function onDone(body,res)
puts("")
puts("res is ")
puts(res)
puts("body is ")
puts(body)
local path = NSDocumentDirectory .. "/" .. "example.doc"
puts("path is " .. path)
local myFile = io.open( path, "w+b" )
myFile:write( tostring(body) )
myFile:close()
end
local targetURL = "http://naldi.olearn.com/example/doc.doc"
wax.http.request{targetURL,format="text",callback=onDone}
Feel free to use the targetURL; it's working now. If you try to
download it using web browser, it will download the correct doc file
and you can open it.
My problems:
[1] Using the code above, the body is "nil". It returns "nil"
also when the format is not specified.
[2] If I change the wax.http.request's format to "binary", it does
show something, but when i tried to write it to a file it complained
that io.write needed a string input, so i converted it to string but
still couldn't open it because it tried to save the binary as string.
I guess my question is, how can I save a binary to a file?
[3] What is the default "format" value for wax.http.request?
Regards,
Naldi
PS: If I use lua's socket.http instead of wax's, the code above (with
little modification to fit lua's socket.http format of course), works
just fine and I can open it.