lua-users home
lua-l archive

Re: Haproxy-LUA-RestAPI call

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


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

AltStyle によって変換されたページ (->オリジナル) /