JAVA全系列 教程
3762个小节阅读:7094.2k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在前两个节课我们己经阻挡了大部分的错误请求,所以 content 阶段就可以“安心”地编写主要的业务逻辑代码:
xxxxxxxxxx
local function action_get()
ngx.req.discard_body() --显示丢失请求体得数据
local t = ngx.time()
ngx.say(ngx.http_time(t)) -- 转换为http格式输出
end
local function action_post()
ngx.req.read_body() -- 要求非阻塞读取请求体
local data = ngx.req.get_body_data() -- 获取请求体得数据
local num = tonumber(data)
if not num then
ngx.log(ngx.ERR,"XXX")
ngx.exit(400) --返回状态码 400 结束请求
end
ngx.say(ngx.http_time(num)) --http格式输出
end
local actions = {GET = action_get,POST = action_post}
local method = ngx.req.get_method() -- 获取对应得处理函数
actions[method]()