如何在快速应用程序中处理Content-Type = application / json; charset = utf-16并发送兼容响应

时间:2019-08-07 07:51:47

标签: node.js express utf-16 utf

我有一个快递服务器,我必须处理带有标头的POST调用: UNICODE:是 内容长度:130 内容类型:application / json; charset = utf-16

并且还必须发送兼容的响应。

我在邮递员中遇到以下错误

<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Error</title>
    </head>
    <body>
        <pre>Bad Request</pre>
    </body>
</html>

这是服务器出错的代码:

app.use(morgan('tiny'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: false }));

在日志中,我发现以下错误:

SyntaxError: Unexpected token # in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError (/home/ubuntu/KountPlatform/node_modules/body-parser/lib/types/json.js:157:10)
    at parse (/home/ubuntu/KountPlatform/node_modules/body-parser/lib/types/json.js:83:15)
    at /home/ubuntu/KountPlatform/node_modules/body-parser/lib/read.js:121:18
    at invokeCallback (/home/ubuntu/KountPlatform/node_modules/raw-body/index.js:224:16)
    at done (/home/ubuntu/KountPlatform/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/home/ubuntu/KountPlatform/node_modules/raw-body/index.js:273:7)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:448:20)
    at endReadableNT (_stream_readable.js:1129:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

0 个答案:

没有答案