Javascript 是否有合适的方法通过React使用fetch()发送POST请求?
我在API服务器端得到的url为None,当使用POSTMAN和其他脚本进行测试时,API工作正常,但是问题在React中发送请求时发生Javascript 是否有合适的方法通过React使用fetch()发送POST请求?,javascript,reactjs,django,api,Javascript,Reactjs,Django,Api,我在API服务器端得到的url为None,当使用POSTMAN和其他脚本进行测试时,API工作正常,但是问题在React中发送请求时发生 const imgLoad = { method: 'POST', headers: { "Content-Type":"application/json" }, body: JSON.stringify({ image_url: imageurl //image url store
const imgLoad = {
method: 'POST',
headers: {
"Content-Type":"application/json"
},
body: JSON.stringify({
image_url: imageurl //image url stored in a variable & I tried using a string but the problem is still there
})
}
fetch("http://127.0.0.1:7000/emotion_detection/detect/", imgLoad)
.then(response => response.json())
.then(data => this.setState({emotion: data}));
使用POSTMAN工具从ReactJS中找到正确的实现方式
var formdata = new FormData();
formdata.append("image_url", `${this.state.input}`);
var requestOptions = {
method: 'POST',
body: formdata,
redirect: 'follow'
};
fetch("http://127.0.0.1:7000/emotion_detection/detect/", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
您遇到了什么错误?这不是一个错误,但是在API服务器端,image_url的值变为None,所以这是我发送请求的方式的问题。