我试图使用Fetch-api在reactjs中运行post api。
我尝试在postman上运行相同的API,并且它已经运行了。
我不知道我错过了什么。
我正在使用的密码。
fetch('url', {
method: 'POST',
mode: "no-cors", // or without this line
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: {
"username": this.state.user_name,
"password": this.state.password
}
})在上面的代码中,我得到了500内部服务器错误
而在正文中,如果我使用Json.stringyfy而不是出错内容类型的。我需要将内容类型作为json-application发送。
如果有任何其他方式发送邮件请求比也告诉我。
谢谢..)
发布于 2017-09-22 07:31:52
你试过使用阿西克斯吗?
示例:
axios.post('url', {
username: 'Fred',
password: 'xyz'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});https://stackoverflow.com/questions/46359107
复制相似问题