Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets 如何在不使用Lua套接字的情况下在Lua中进行HTTP POST_Sockets_Http_Tcp_Lua - Fatal编程技术网

Sockets 如何在不使用Lua套接字的情况下在Lua中进行HTTP POST

Sockets 如何在不使用Lua套接字的情况下在Lua中进行HTTP POST,sockets,http,tcp,lua,Sockets,Http,Tcp,Lua,我试图从一个Lua脚本化的硬件向外部服务器发送httppost命令。为此,我必须创建一个tcpConnection,然后执行一个tcpSend()命令。我已经用wireshark确认了TCP连接,我看到它发送了HTTPGET命令,但我不知道如何发送post。我试着在代码中更改GET-to-POST,但没有效果 debugConsole = -20 while true do --Opening connection to remote host debugConsole = tcp

我试图从一个Lua脚本化的硬件向外部服务器发送httppost命令。为此,我必须创建一个tcpConnection,然后执行一个tcpSend()命令。我已经用wireshark确认了TCP连接,我看到它发送了HTTPGET命令,但我不知道如何发送post。我试着在代码中更改GET-to-POST,但没有效果

debugConsole = -20

while true do



--Opening connection to remote host

  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)

--Printing response from remote host

  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 

这个答案显示了HTTP POST请求应该如何格式化:如果这对您没有帮助,那么发布您的
tcpConnect
tcpSend
responseSubstr
tcpClose
httpRequest
函数可能会很有用,这样我们就可以自己执行测试了……感谢您的回复。因此,该设备是由Web X600M控制的。这些功能内置于该单元中。我不确定这是否有帮助。可能是您可以在API周围实现LuaSocket cmpatiable包装器,并使用LuaSocket的HTTP模块。您是否尝试过按照我发布的链接格式化您的请求?如果有,是否可以在服务器应用程序中查看请求?你能在wireshark中看到它吗?您的服务器是否有您可以发布的日志?此答案显示了HTTP post请求的格式:如果这对您没有帮助,那么发布您的
tcpConnect
tcpSend
responseSubstr
tcpClose
httpRequest
函数可能会很有用,所以我们可以自己进行测试…谢谢你的回复。因此,该设备是由Web X600M控制的。这些功能内置于该单元中。我不确定这是否有帮助。可能是您可以在API周围实现LuaSocket cmpatiable包装器,并使用LuaSocket的HTTP模块。您是否尝试过按照我发布的链接格式化您的请求?如果有,是否可以在服务器应用程序中查看请求?你能在wireshark中看到它吗?您的服务器是否有可以发布的日志?