OpenResty发送HTTP请求

OpenResty第三方插件lua-resty-http发送HTTP请求

插件GitHub地址https://github.com/ledgetech/lua-resty-http

将插件的http.lua http_connect.lua http_headers.lua三个文件加入openResty的lualib/resty目录中

sendHttp.lua

local http = require('resty.http')
local httpObj = http.new()
local res, err = httpObj:request_uri('http://127.0.0.1:5000/students', {
  method = 'GET'
})
if not res then
  ngx.log(ngx.ERR, "request failed: ", err)
  return
end
ngx.say(res.body)