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.

How to response http post with lua
#1
I have the code below to receive an http post from external server via port 8083. After that, how can I response so the server would get the http status code 200?


Code:
local socket = require("socket")
local server = assert(socket.bind("*", 8083))
local tcp = assert(socket.tcp())

while 1 do
  local client = server:accept()
  line = client:receive()
  client:send('HTTP/1.1 200 OK \n')
end
Reply
#2
You can do this with the built-in web server and .lp file. Save the code as post.lp file and upload to LM via FTP using apps username (you might need to enable FTP in System config). If your HTTP client supports basic auth then you can upload post.lp into user directory on the FTP. If it does not then you can use public directory. The HTTP path will be either http://LM_IP/user/post.lp or http://LM_IP/public/post.lp

This example logs data that has been sent via POST in JSON format:
Code:
<?

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

log(data)
Reply
#3
I save the code as post.lp

[Image: JfjpdfE.png]

Then I upload that file to folder user in LM (can't upload to folder public since it show error: Could not creat file like in screenshot.


[Image: kMyKI69.png]


Now what would I should input here? and the local port should be 21 FTP or 80 HTTP?

[Image: eLCaznS.png]
Reply
#4
Use port 80 for HTTP and port 443 for HTTPS.
Reply
#5
Thank you very much. It worked
Reply


Forum Jump: