如何在Lua中进行HTTP POST而不使用Lua Socket

我正试图从一块用 Lua 脚本编写的硬件向外部服务器发送 HTTP POST 命令。为了这样做,我必须创建一个 tcpConnect 连接,然后执行 tcpSend() 命令。我已经使用 Wireshark 确认了 TCP 连接,并看到它发送了 HTTP GET 命令,但我不知道如何发送 POST。我已经尝试在代码中将 GET 更改为 POST,但没有成功。

debugConsole = -20

while true do

--打开到远程主机的连接

  debugConsole = tcpConnect("192.168.1.1", 80, 100)

  print("TCP connect " .. debugConsole)

  debugConsole = tcpSend("GET /api/v1/profiles/active_profiles.json?profile=5&expiry=1&duration=0&auth_token=2e608b72390a866f4bc7bbb6db63a1aa HTTP/1.1 \r\n\r\n")

  print("TCP Send = " .. debugConsole)

--打印来自远程主机的响应

  print(responseSubstr(0, 500))

  debugConsole = tcpClose()

  print("TCP Close = " .. debugConsole)

  debugConsole = httpRequest("http://192.168.1.1/api/v1/profiles/active_profiles.json?profile=5&expiry=1&duration=0&auth_token=2e608b72390a866f4bc7bbb6db63a1aa", 10)

    print("HTTP Request = " .. debugConsole)

  print(" ")

  sleep (10000)

end
点赞