其他分享
首页 > 其他分享> > 没有身体分析器的表达在哪里输入JSON?

没有身体分析器的表达在哪里输入JSON?

作者:互联网

我了解人体分析仪及其作用.我很好奇,知道使用Express时请求中的数据在哪里.在主体解析器解析输入之前,存在哪种格式.

// 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服务器功能应用扩展,包括扩展本机的Request和Response对象.因此,您也可以像对待native request object as well一样对待Express请求

标签:node-js,express,body-parser,javascript,node-modules
来源: https://codeday.me/bug/20191108/2009066.html