最近突然想起来post请求的三种方式,但是具体的流程有些遗忘,今日复习并记录一下具体操作。
服务器选择的是 node
1、application/json
配置请求头 headers :{"content-type":"application/json"}
const bodyParser = require("body-parser");
app.use(bodyParser.json());
2、application/x-www-form-urlencoded
headers:{ "content-type":"application/x-www-form-urlencoded" },
app.use(bodyParser.urlencoded({extended:true}));
3、formdata
const formidable = require("formidable");
app.post("接口",function (req,res) {
const form = new formidable.IncomingForm();
form.parse(req,function (err,params,file) {
err 错误信息 params 数据 file 文件或者图片
})
})
})