简体   繁体   English

如何使用LuaSec发送HTTPS

[英]How can i use LuaSec for sending in HTTPS

In my script, i use the library LuaSocket to send a XML-code. 在我的脚本中,我使用库LuaSocket发送XML代码。 This works fine with the following code: 使用以下代码可以正常工作:

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);
 }

But now i'll send the XML with the protocoll HTTPS with a certificate. 但是现在,我将使用带有证书的协议HTTPS发送XML。 I know that i can use LuaSec but how? 我知道我可以使用LuaSec,但是如何使用? Can someone tell me, how i can modify the code to a working code for HTTPS? 有人可以告诉我,我如何将代码修改为HTTPS的有效代码?

Just add: 只需添加:

local https = require("ssl.https")

and replace: 并替换:

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

with

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

Be sure to have installed LuaSec: 确保已安装LuaSec:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM