Sockets Lua HTTP下载并保存到文件

Sockets Lua HTTP下载并保存到文件,sockets,http,download,lua,luasocket,Sockets,Http,Download,Lua,Luasocket,我正在尝试下载内容,然后将其保存到xml文件中。我得到的代码是: 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!") 它运行,但文件仍然为空。我

我正在尝试下载内容,然后将其保存到xml文件中。我得到的代码是:

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!")

它运行,但文件仍然为空。我能在这里得到一些帮助吗?

这是一个语法错误。您混合了两种调用http.request的方式。使用

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

非常感谢,有时候工作累了会让你犯这样的错误。