lua-users home
lua-l archive

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


Thanks, Sean Conner,

I have updated the request and the response is in the red color, still am I missing anything?

core.Debug("actionlua called")
function check_ip(txn, addr,port)
core.Debug("actionlua called")
if not addr then addr ='3.226.158.233' end
    if not port then port = 443 end
    -- Set up a request to the service
    local payload = [[{"email":"evtest@yopmail.com"}]]
    local hdrs = {
        [1] = string.format('host: %s:%s', addr,port),
        [2] = 'Accept: application/json',
        [3] = 'Content-Type: application/json',
        [4] = string.format('Content-Length: %d',#payload)
    }
    local req = {
        [1] = 'POST /evl/evIDLookUp HTTP/1.1',
        [2] = table.concat(hdrs, '\r\n'),
        [3] = '\r\n',
        [4] = payload
    }
    req = table.concat(req,  '\r\n')
     print("req::",req)
    -- Use core.tcp to get an instance of the Socket class
    local socket = core.tcp()
    -- Connect to the service and send the request

local connection = socket:connect(addr,port)
print("connection::",connection)  -- connection:: 1
local res = socket:send(req) 
print("res::",res) -- res::168
local rec = socket:receive("*a")
print("rec::",rec) -- rec:: nil
end
core.register_action('checkip', {'http-req'}, check_ip)

Thanks,
B.MuraliMohanReddy

On Mon, Mar 2, 2020 at 10:15 AM Sean Conner <sean@conman.org> wrote:
It was thus said that the Great murali once stated:
> Yes, I have gone through these documents and required help at Socket class
> send and receive functions with POST and GET request sending to third party
> service.
> Here I will provide my request as string please help us providing syntax,
> how to send in Socket's send method and receive the response.
> request:
> https://rest-uat-corretto.evergent.com:443/evl/evIDLookUp?email=evtest@yopmail.com

  Going back to your original post, you gave the following code:

    local payload = [[{"email":"evtest@yopmail.com"}]]

    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')

  Your request is formatted incorrectly.  You have the payload between the
request and the headers, which isn't allowed by the HTTP spec.  You are also
neglecting to set the Content-Length header.  It should be:

        local hdrs = {
          string.format('Host: %s:%s',addr,port),
          'Accept: application/json',
          'Content-Type: application/json',
          string.format('Content-Length: %d',#payload)
        }

        local res = {
          'POST /evl/evIDLookU HTTP/1.1',
          table.concat(hdrs,'\r\n'),
          '\r\n',
          payload
        }

  -spc



--







B.Murali Mohan Reddy