Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否有合适的方法通过React使用fetch()发送POST请求?_Javascript_Reactjs_Django_Api - Fatal编程技术网

Javascript 是否有合适的方法通过React使用fetch()发送POST请求?

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

我在API服务器端得到的url为None,当使用POSTMAN和其他脚本进行测试时,API工作正常,但是问题在React中发送请求时发生

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,所以这是我发送请求的方式的问题。