OpenResty get_body_data 无法获取请求体数据

OpenResty Lua About 656 words

问题

在使用application/json提交请求体数据时,ngx.req.read_body()获得的请求体参数为nil

情况一

在获取请求体前未使用ngx.req.read_body()。必须先读取请求体,才能解析。

ngx.req.read_body()
local body_data = ngx.req.get_body_data()

情况二

已经添加ngx.req.read_body()代码,但还是解析为nil

发现提交的请求体大于16K,需增大客户端请求体缓存大小client_body_buffer_size的值,64位系统默认16K

修改client_body_buffer_size5MB

location = /post/publish {
    client_body_buffer_size 5M;
    access_by_lua_file z_blog_openresty/src/access/auth.lua;
    content_by_lua_file z_blog_openresty/src/content/dashboard/post.lua;
}

参考

https://github.com/openresty/lua-nginx-module#ngxreqget_body_data

http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_buffer_size

Views: 3,358 · Posted: 2020-11-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh