local s = ngx.socket.tcp()
local host = "127.0.0.1"
local port = 80
local ok, err = s:connect(host,port)
if not ok then
ngx.say("failed to connect: " .. err)
return
end
local data = ""
.. "Host: localhost\r\n"
.. "Connection: close\r\n"
.. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n"
.. "User-Agent: lua\r\n"
.. "Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\r\n"
.. "Content-Type: application/x-www-form-urlencoded\r\n"
.. "Content-Length: 3\r\n\r\n"
.. "b=4"
local bytes, err = s:send(data)
if not bytes then
ngx.say("failed to send query")
return
end
local read_headers = s:receiveuntil("\r\n\r\n")
local headers, err = read_headers()
if not read_headers then
ngx.say("failed to read response headers:", err)
return
end
--ngx.say(headers)
local body,err = s:receive("*a")
if not body then
ngx.say("failed to read response body", err)
return
end
--ngx.say('4')
ngx.say("[".. body .."]")