09.02.2023, 10:17
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:
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
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