fetch(url, {
method: 'POST', // 请求方法
headers: { // 请求头部信息
'Content-Type': 'application/json', // 设置 Content-Type 为 JSON 格式
'Authorization': 'Bearer <token>', // 设置 Authorization 头部,用于身份验证
// 其他自定义头部...
},
body: JSON.stringify(data) // 请求体内容,需转换为 JSON 格式
})
.then(response => response.json())
.then(data => {
// 处理返回的数据
})
.catch(error => {
// 处理错误
});