request help: body_filter how to send request in apisix #5677
Replies: 11 comments 2 replies
-
we can use a 0 delay |
Beta Was this translation helpful? Give feedback.
-
This doesn't seem to solve my problem
in header_filter.
in body_filter |
Beta Was this translation helpful? Give feedback.
-
I cannot got what you want to do. BTW, ngx.redirect is unavailable in |
Beta Was this translation helpful? Give feedback.
-
ngx.req.set_uri it seem can solve my problem |
Beta Was this translation helpful? Give feedback.
-
As I've already said, if you want to send the request in the body_filter phase, you can use ngx.timer to do so,see: https://moonbingbing.gitbooks.io/openresty-best-practices/content/ngx_lua/timer.html |
Beta Was this translation helpful? Give feedback.
-
you can last request returned Status get by |
Beta Was this translation helpful? Give feedback.
-
yes it can slove my problem ,i write like this `function _M.body_filter(conf, ctx) end` but my ngx.socket.tcp() always return 400 Bad Request,how can i reslove this problem |
Beta Was this translation helpful? Give feedback.
-
i use tcp.socket.connect always return use https://github.com/openresty/lua-nginx-module#tcpsockconnect example |
Beta Was this translation helpful? Give feedback.
-
This is a matter of the request method or request parameters. It has to do with your own service.
This is where your local network environment is unable to resolve the domain name and you can use another domain name that can resolve. |
Beta Was this translation helpful? Give feedback.
-
I will turn this issue into a discussion, which has nothing to do with the project. |
Beta Was this translation helpful? Give feedback.
-
你可以利用resty.http库来发发送同步的http请求,像下面这样: local http = require "resty.http" -- 加载 lua-resty-http 库
httpc, err = http:new() -- 创建 http 连接对象
httpc:set_timeout(time) -- 注意名字里有一个下划线
httpc:set_timeout(connect_timeout, -- 同上
send_timeout, read_timeout)
local res, err = httpc:request_uri( -- 发送 HTTP 请求,默认是 GET
'http://www.baidu.com', -- 指定 IP 地址
{path = '/echo', -- 指定具体路径
query = {name = 'chrono'}} -- 请求的参数,使用 Lua 表
)
if not res then -- 检查请求是否成功
core.log.error("failed to request : ", err)
return
end
core.log.info("args:", type(args))
core.log.info("res.body:",res.body) -- 输出响应体
end
local resp = ""
local ok, err = ngx.timer.at(0, push_data, ngx.var.args)
if not ok then
ngx.log(ngx.ERR, "failed to create timer: ", err)
return
end
ngx.arg[1] = "success"
ngx.arg[2] = true`
|
Beta Was this translation helpful? Give feedback.
-
Issue description
i want send request in body_filter,based on last request returned Status to send different req
Environment
apisix version
):uname -a
):nginx -V
oropenresty -V
):curl http://127.0.0.1:9090/v1/server_info
to get the info from server-info API):luarocks --version
):Beta Was this translation helpful? Give feedback.
All reactions