lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Team,

I am new to LUA programming language, I am trying to call external service https call from LUA and got success, but the same thing is not working when integrating with HAProxy.Could you please help us providing sample Rest POST request calls from LUA Script using HAProxy compatible SOCKET functions.
Here I am attaching my LUA script and let us know is am missing anything?

core.Debug("actionlua called")
function check_ip(txn, addr,port)
core.Debug("actionlua called")
if not addr then addr ='' end
    if not port then port = 443 end
    -- Set up a request to the service
    local payload = [[{"email":""}]]

    local hdrs = {
        [1] = string.format('host: %s:%s', addr,port),
        [2] = 'accept: application/json',
        [3] = 'Content-Type: application/json'

    local req = {
        [1] = 'POST /evl/evIDLookU HTTP/1.1',
        [2] = payload,
        [3] = table.concat(hdrs, '\r\n'),
        [4] = '\r\n'

    req = table.concat(req,  '\r\n')
    -- Use core.tcp to get an instance of the Socket class
    local socket = core.tcp()

    -- Connect to the service and send the request

 if socket:connect(addr,port) then
     if socket:send(req) then
  if socket:send(req) then
        -- Get response body, if any
           local content = socket:receive("*a")
      core.Alert('Could not connect to IP Checker server (connect)')
    -- The request should be blocked
    --txn:set_var('req.blocked', true)
core.register_action('checkip', {'http-req'}, check_ip)



B.Murali Mohan Reddy