发送from-data格式的请求
apt.sendRequest({
url:“http://127.0.0.1:8888/login”,
method:“POST”,
headers:{
“cookie”:“a=1;b=2”,
“content-type”:“multipart/form-data”
},
timeout:“25000”,
formData:{“name”:“xiaoming”,“pwd”:123}
}, function (response) {
console.log(response);
});

发送application/x-www-form-urlencoded格式的请求
apt.sendRequest({
url:“http://127.0.0.1:8888/login”,
method:“POST”,
headers:{
“cookie”:“a=1;b=2”,
“content-type”:“application/x-www-form-urlencoded”
},
timeout:“25000”,
form:“a=1”
}, function (response) {
console.log(response);
});

发送application/json格式的请求
apt.sendRequest({
url:“http://127.0.0.1:8888/login”,
method:“POST”,
headers:{
“cookie”:“a=1;b=2”,
“content-type”:“application/json”
},
timeout:“25000”,
body:"{a:1}"
}, function (response) {
console.log(response);
});

请求方式大比拼:from-data、x-www-form-urlencoded与JSON
本文详细介绍了如何使用不同的数据格式发送POST请求,包括multipart/form-data、application/x-www-form-urlencoded和application/json,以及相应的示例代码。
750

被折叠的 条评论
为什么被折叠?



