scls
Newcomer
- Joined
- Mar 10, 2021
- Messages
- 10
- Reaction score
- 2
Hello,
I'm trying to download a file using http.request using Lua 5.4.2 / LuaRocks 3.7.0 / luasocket-3.0rc1-2.src.rock and this code
unfortunately the content of "AD-2.LFBI.pdf" file is not a real PDF file but an HTML file showing a redirect. See below
So it seems that http.request doesn't follow redirects.
How can I handle that?
Kind regards
I'm trying to download a file using http.request using Lua 5.4.2 / LuaRocks 3.7.0 / luasocket-3.0rc1-2.src.rock and this code
Lua:
local http = require("socket.http")
url = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_07_OCT_2021/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2.LFBI.pdf"
local body, code, headers, status = http.request(url)
if not body then error(ret_code) end
oaci_code = "LFBI"
local fname = string.format("AD-2.%s.pdf", oaci_code)
local f = assert(io.open(fname, 'wb')) -- open in "binary" mode
f:write(body)
f:close()
unfortunately the content of "AD-2.LFBI.pdf" file is not a real PDF file but an HTML file showing a redirect. See below
HTML:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_07_OCT_2021/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2.LFBI.pdf">here</a>.</p>
</body></html>
So it seems that http.request doesn't follow redirects.
How can I handle that?
Kind regards
Last edited: