This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LM as REST server
#1
Hello.
I have to communicate with an external point of sales terminal. The main communication is done via REST, that’s the easy part and is working already. My problem is, that the terminal uses a callback function to inform the LM when a button is pressed by the user. So I have to implement a Server that listens for incoming data. The data is in HTML and looks like that:
 
POST / HTTP/1.1(
Accept: text/plain, application/json, application/*+json, */*(
Content-Type: application/json(
Authorization: CPS apikey="xxxxxxxx"(
User-Agent: Java/11.0.14.1(
Host: xxx.xxx.xxx.xxx:xxx(
Connection: keep-alive(
Content-Length: 71(
(
{"serialNumber":"xxxx","screenId":"Screen-1","response":"ok"}
 
I have tried to use the following code:
Code:
local socket = require("socket")
local server = assert(socket.bind("*", 4001))
local header
while 1 do
  local client = server:accept()
  local line = client:receive()
  header = line
  while (#line > 0) do
    line = client:receive()
    header = header .. line
  end
  log(header) 
end

 
But so I can only receive the header. I think that I have to use also ltn12 to get the body data, but I have no idea how. I also tried to use copas but this was also not successful.
I would be quite thankful for some help.
 
Thanks,
Christian
Reply


Messages In This Thread
LM as REST server - by Christian_EWW - 09.02.2023, 10:17
RE: LM as REST server - by admin - 09.02.2023, 11:12
RE: LM as REST server - by Christian_EWW - 09.02.2023, 14:46
RE: LM as REST server - by admin - 09.02.2023, 14:48

Forum Jump: