我知道 body-parser
及其作用。我很想知道在使用 express
时请求的数据在哪里。在 body-parser
解析输入之前存在哪种格式。
// parse urlencoded types to JSON
app.use(bodyParser.urlencoded({
extended: true
}));
// parse various different custom JSON types as JSON
app.use(bodyParser.json({ type: 'application/*+json' }));
// parse some custom thing into a Buffer
app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }));
// parse an HTML body into a string
app.use(bodyParser.text({ type: 'text/html' }));
如果不使用这些,数据将在哪里?它将以哪种格式提供?
最佳答案
Node documentation 中对此进行了相当详尽的介绍。 .
The request object that's passed in to a handler implements the ReadableStream interface. This stream can be listened to or piped elsewhere just like any other stream. We can grab the data right out of the stream by listening to the stream's 'data' and 'end' events.
Express 实际上是在对 Node.js HTTP 服务器功能应用扩展,包括扩展 native Request 和 Response 对象。因此,您同样可以像处理 native request object as well 一样处理 Express 请求。
关于javascript - 没有正文解析器的 Express 输入 JSON 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52122643/