1

I am trying to send a HTTP POST command to an external server from a Lua scripted piece of hardware. In order to do so I have to create a tcpConnection and then do a tcpSend() command. I have confirmed the TCP Connection using wireshark and I have seen it send the HTTP GET command but I do not know how to send a post. I have tried to just change the GET to POST in the code but no avail.

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 
Colonel Thirty Two
  • 18,351
  • 7
  • 32
  • 69
  • This answer shows how an HTTP POST request should be formatted: http://stackoverflow.com/a/14551219/570336 If that doesn't help you, it might be useful to post your `tcpConnect`, `tcpSend`, `responseSubstr`, `tcpClose` and `httpRequest` functions, so we can perform tests ourselves... – Henrik Ilgen Jan 27 '16 at 17:23
  • Thanks for the reply. So this device is a Control by Web X600M. [link](http://www.controlbyweb.com/x600m/) those functions are built in to the unit. I am not sure if that helps. – Andrew Macaulay Jan 27 '16 at 18:42
  • May be you can implement LuaSocket cmpatiable wrapper around your API and use HTTP module from LuaSocket. – moteus Jan 28 '16 at 12:39
  • Have you tried formatting your request as per the link I posted? If you have, can you see the request in your server application? Can you see it in wireshark? Does your server have any logs that you can post? – Henrik Ilgen Jan 29 '16 at 06:52

0 Answers0