OpenResty 返回中文乱码问题

OpenResty Lua JSON About 337 words

描述

接口中使用ngx.say(json.encode)编码json字符串,返回中文乱码。

{"msg":"请求成功","code":0}

解决

设置Content-Type时加上charset=utf8

server {
    listen       8080;
    server_name  localhost;
    default_type  'applicaiton/json;charset=utf8';
    charset utf-8;
    ...
}

也可以在header_filter阶段赋值header

ngx.header.content_type="application/json;charset=utf8"
Views: 6,308 · Posted: 2020-03-20

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh