文章目录
- 我们通常的数据发送格式是这样子的:
-
那如果我们要把他改成下面
Form Data
格式该怎么做呢:
-
核心代码就是:
headers: {
"content-type": "application/x-www-form-urlencoded",
},
// body 为字符串格式,多个参数以 & 连接,可以使用模板字符串 `${}` 进行动态赋值
body: "pageId=6271&editRelease=true",
- 具体实现:
fetch("https://test.com", {
"headers": {
"accept": "application/json, text/plain, */*",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded",
},
"body": "pageId=6271&editRelease=true",
"method": "POST",
"mode": "cors",
"credentials": "include"
})
.then(res => res.json())
.then(res => {
console.log(res)
})
.catch(err => {console.log(err)})