Lua - Download via http and https (Lua 5.1 embedded)

Viewed 40

I’m sure this is not a unique question about Lua 5.1 (especially an embedded instance, where you can’t install modules, your only options is pure Lua files/reference, therefore I can’t install something like luacurl ). I’ve seen this matter referred to in various SO places, and tried them, but I can’t seem to find a fix to make an https file download request work in this particular Lua environment..

To give you an example, the code below aims to download 2 different files, the http call works fine, returning a 200 code, but the https one doesn’t, it doesn’t return anything ?

Both targets can be access directly via the browser.. Please could some highlight what I’m missing in the https call to make it work?

print("--------DOWNLOAD http---------")

local http = require("socket.http")
local body, code = http.request("http://pbs.twimg.com/media/CCROQ8vUEAEgFke.jpg")
print(code)
if not body then error(code) end
local f = assert(io.open('mnt/nas/webtest1.jpg', 'wb')) -- open in "binary" mode
f:write(body)
f:close()

print("--------DOWNLOAD https---------")

local https = require "ssl.https" --luasec
local body, code = https.request("https://u.cubeupload.com/jbcooper/16146313918060.jpg")
print(code)
if not body then error(code) end
local f = assert(io.open('mnt/nas/webtest2.jpg', 'wb')) -- open in "binary" mode
f:write(body)
f:close()

As requested, the following returns nothing at all..

local https = require "ssl.https" --luasec
print(https.request("https://u.cubeupload.com/jbcooper/16146313918060.jpg"))

If it helps, if I run the following it returns 0.4

local https     = require("ssl.https") 
local httpsVersion = string.sub(https._VERSION,1,3)
print (httpsVersion)
0 Answers
Related