Try to follow 301/302 redirected URLs

This commit is contained in:
Gökçen Eraslan 2014-12-21 18:19:33 +01:00
parent 9d161163f4
commit f3b522cde8

View File

@ -33,7 +33,9 @@ end
function download_to_file( url , noremove ) function download_to_file( url , noremove )
print("url to download: "..url) print("url to download: "..url)
req, c, h = http.request(url) local ltn12 = require "ltn12"
local respbody = {}
one, c, h = http.request{url=url, sink=ltn12.sink.table(respbody), redirect=true}
htype = h["content-type"] htype = h["content-type"]
vardump(c) vardump(c)
print("content-type: "..htype) print("content-type: "..htype)
@ -55,7 +57,7 @@ function download_to_file( url , noremove )
end end
end end
file = io.open(file_path, "w+") file = io.open(file_path, "w+")
file:write(req) file:write(table.concat(respbody))
file:close() file:close()
if noremove == nil then if noremove == nil then