2014-06-24 36 views
0

在我的腳本中,我使用庫LuaSocket發送XML代碼。這與以下代碼正常工作:如何使用LuaSec以HTTPS發送

local request_body = (XMLHeader..XMLBody); 
local response_body = {} 

local res, code, response_headers = socket.http.request 
{ 
    url = "http://blabla.com/v01/Authenticatie.svc"; 
    method = "POST"; 
    headers = 
{ 
    ["Content-Type"] = "application/soap+xml; charset=utf-8"; 
    ["Content-Length"] = string.len(request_body); 
    ["Accept-Encoding"] = "gzip, deflate"; 
    ["Connection"] = "Keep-Alive"; 
}; 
source = ltn12.source.string(request_body); 
sink = ltn12.sink.table(response_body); 
} 

但現在我會發送帶有證書的protocoll HTTPS的XML。我知道我可以使用LuaSec但是如何?有人可以告訴我,我可以如何修改代碼爲HTTPS的工作代碼?

回答

4

只需添加:

local https = require("ssl.https") 

並替換:

local res, code, response_headers = socket.http.request 

local res, code, response_headers = https.request 
{ 
    url = "https://blabla.com/v01/Authenticatie.svc"; 

確保已經安裝LuaSec:

luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib64/ #CentOS 
# or 
luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu # Ubuntu