简体   繁体   English

如何在nodejs中支持application / json,application / x-www-form-urlencoded和multipart / form-data的请求或响应主体

[英]how to support request or response bodies for application/json, application/x-www-form-urlencoded and multipart/form-data in nodejs

actually I am newbie, I want to use express in my web application, So I want support all the requests and response in my application should support 实际上我是新手,我想在我的Web应用程序中使用express,所以我希望支持我的应用程序中的所有请求和响应应该支持

application/json, application/x-www-form-urlencoded and multipart/form-data application / json,application / x-www-form-urlencoded和multipart / form-data

express is rather smart, and will automatically determine the header type, you can even use res.send(JSONObj) to send an object directly as JSON. express非常智能,并且会自动确定头类型,你甚至可以使用res.send(JSONObj)直接发送一个对象作为JSON。 If you want to manually set the header you can do so by using res.setHeader('Content-Type', 'application/json') before you send any data. 如果要手动设置标题,可以在发送任何数据之前使用res.setHeader('Content-Type', 'application/json')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Axios 在 application/x-www-form-urlencoded 中编码 JSON 数据? - How to encode JSON data in application/x-www-form-urlencoded using Axios? request.post继续覆盖内容类型作为content-type:application / x-www-form-urlencoded当指定表单数据时 - request.post continues to override content-type as content-type: application/x-www-form-urlencoded when form-data is being specified 节点js如何识别邮递员扩展客户端请求来自“表单数据”或“ x-www-form-urlencoded” - node js how to identify postman extention client request came from “form-data” or “x-www-form-urlencoded” 如何使用“内容类型”:“ application / x-www-form-urlencoded”发出发布请求? - How to make a Post request with “content type”: “application/x-www-form-urlencoded”? 如何使用 simple-oauth2 库发出请求 application/x-www-form-urlencoded? - how to use the simple-oauth2 library to make request application/x-www-form-urlencoded? 如何将Content-Type:appication / x-www-form-urlencoded更改为application / json? - How to change Content-Type: appication/x-www-form-urlencoded to application/json? 如何在 node.js 中发布内容类型 ='application/x-www-form-urlencoded' 的数据 - how to post data in node.js with content type ='application/x-www-form-urlencoded' 如何在 Node 服务器上读取以 application/x-www-form-urlencoded 格式接收的数据? - How can I read the data received in application/x-www-form-urlencoded format on Node server? 使用“Content-Type”:“application/x-www-form-urlencoded”从 axios 发送帖子请求会给出 401 Unauthorized 响应 - Sending post request from axios with "Content-Type" : "application/x-www-form-urlencoded" gives an 401 Unauthorized response Angular $ HTTP可与CORS和application / x-www-form-urlencoded一起使用,但可通过application / json获得OPTIONS 404 - Angular $HTTP works with CORS and application/x-www-form-urlencoded but gets OPTIONS 404 with application/json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM