【发布时间】:2022-10-15 18:10:12
【问题描述】:
我在请求标头中的内容类型是 text/plain 但我设置了 content-type : application/json 和 mode : cors 。完成所有这些之后,我得到了文本/纯内容类型
export const signin = async({email, password}) =>{
console.log(email);
console.log(password);
const _data = {
"email" : email,
"password" : password
}
try{
const response = await fetch(apiUrl+"/api/user/signin",{
method : 'POST',
mode: 'cors',
body: JSON.stringify(_data),
header :{
"Content-Type": "application/json",
"Content-Length": JSON.stringify(_data).length
},
});
if(!response || !response.ok){
// throw new Error(response.json());
return await response.json();
}
return await response.json();
}catch(err){
console.log(err);
return {error : err.message};
}
};
以上是我的代码。请帮我
【问题讨论】:
-
由于这个 json 数据没有到达后端(也许)
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如它目前所写的那样,很难准确地说出你在问什么。
标签: node.js mongodb post backend fetch-api