user2779657
user2779657

Reputation: 99

Lua HTTP download and save to file

I'm trying to download and then save the contents to a xml file. The code I got is:

local filePath = currentDir().."/file.xml"

local http  = require("socket.http")
local xFile = io.open(filePath, "w")
local save = ltn12.sink.file(xFile)

http.request{addr, sink = save }
print("Done!")

It runs but the file is still empty. Can I get some help here please?

Upvotes: 3

Views: 2198

Answers (1)

robinkc
robinkc

Reputation: 1348

Its a syntactical mistake. You mixed two styles of calling http.request. Use

http.request{url = addr, sink = save } 

Upvotes: 4

Related Questions