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
#2
If you can specify a custom URL (not just http://IP/) then you can use server-side .lp scripting.
See this for more info: https://forum.logicmachine.net/showthrea...6#pid28956
Code:
<?

require('apps')
data = ngx.req.get_body_data()

if data then
  data = json.pdecode(data)
  log(data)
end
Reply
#3
Thanks.
That is working, but not really my prefered way of doing it.
The cons are:
#I have to switch off user authentication
#Can't use an other port
#Harder to read and maintain code
Is there no other way?
Thanks
Reply
#4
You can always write your own HTTP server using scripts if you want Smile
Check if you can put username and password in the URL. If this does not work you can use public directory instead of user. It does not have any authentication checks.
Reply


Forum Jump: