出于散列和验证目的,application/json
的原始正文(未解析)需要发布请求。
环回 4 是否为此提供了任何方法? Request.body
被解析为 json。
最佳答案
您可以通过提供以下 requestBodySpec
来获取原始体:
@post('/raw-body-post')
async rawBodyPost(
@requestBody({
description: 'Raw Body', // Description can be anything
required: true,
content: {
'application/json': { // Make sure this matches the POST request type
'x-parser': 'raw', // This is the key to skipping parsing
schema: {type: 'object'},
},
},
}) body: Buffer
) {
const rawBody = body.toString('utf8');
...
}
关于loopback4 - Loopback 4 提取 POST 请求的原始正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63072039/