Lua中使用ESP8266进行HTTPS请求的问题

如何在ESP8266中使用HTTPS POST和请求体参数发送数据? 我尝试使用在https://nodemcu.readthedocs.io提供的HTTP和net/TLS模块。 我得到了以下错误

E:M 528 HTTP client: Disconnected with error: 46

使用TLS

srv = tls.createConnection()
srv:dns(api, function(conn, ip)
  api = ip
  print("TLS" .. api)
end)
srv:on("receive", function(sck, c)
  print(c .. "success tls")
end)
srv:on("connection", function(sck, c)
  sck:send("GET /test HTTP/1.1\r\n" ..
    "Host: " .. api .. "\r\n" ..
    "Connection: keep-alive\r\n" ..
    "Accept: */*\r\n" ..
    "\r\n")
end)
srv:connect(443, "demo.com")

HTTP模块

http.post("https://demo.com/test", 'Content-Type:application/json\r\nConnection: keep-alive\r\n' { data }, function(code, data)
  if (code < 0) then
    print("请求失败")
  else
    print(code)
    print(data)
  end
end)
点赞