最后记得加个定时任务清空缓存,好让他更新
local http = require "resty.http"
local FilePath = "/opt/www/gethome/"
function IfSave(FileName)
local f = io.open(FileName,"r")
if(f == nil) then
return false
end
f:close()
return true
end
ngx.req.read_body()
local post_body_tab = ngx.req.get_body_data()
local FilePathEnd = FilePath .. post_body_tab
--local post_body_tab = ngx.req.get_post_args()
--for k, v in pairs(post_body_tab) do
-- ngx.say(k,":",v)
--end
--local FilePathEnd = FilePath .. "test"
--local file = io.open(FilePathEnd,"w+")
--file:write(post_body_tab)
--file:close()
local request_url = "http://172.20.4.35:31023/home/getHome"
::lable1:: if IfSave(FilePathEnd) then
local file = io.open(FilePathEnd,"r")
local content = file:read('*all')
file:close()
ngx.say(content)
else
local httpc = http.new()
local restry
local file = assert(io.open(FilePathEnd, "w+"))
local res, err = httpc:request_uri(request_url, {
method = "POST",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
["access_token"] = "ad93e134-5b79-4dc5-93e1-345b79fdc522"
},
body = FilePathEnd
})
restry = res.body
file:write(restry)
file:close()
goto lable1
end