function _M.access(conf, ctx)
-- 引入resty的http请求模块
local http = require("resty.http")
-- 新建一个http请求
local httpc = http.new()
-- 负载均衡的节点列表
local hosts = {}
hosts["192.168.123.131:81"] = 1
hosts["192.168.123.131:82"] = 1
hosts["192.168.123.131:83"] = 1
hosts["192.168.123.131:84"] = 1
-- 发送一个http请求
local resp, err = httpc:request_uri("http://192.168.123.119:82/send", {
method = "GET",
headers = {
-- 设置发送的数据类型
["Content-Type"] = "application/json"
},
body = core.json.encode(hosts)
})
--如果请求为空,那么就返回错误信息
if not resp then
ngx.say("request error :", err)
return
end
--返回请求结果
ngx.say(resp.body)
--关闭http请求
httpc:close()
end
无标签
发布日期:
2020-12-25
文章字数:
152
阅读时长:
1 分
阅读次数: