我想将JSON数据发送到其他计算机Web API服务器。我无法在Reactjs中使用Axios发送数据,但是Postman正在工作。这些计算机在同一网络上工作。
控制台错误;
选项https://192.168.1.214:5001/api/books 405(不允许使用方法)
访问“ https://192.168.1.214:5001/api/books”处的XMLHttpRequest 来自来源“ http://localhost:3000”的信息已被CORS政策阻止: 对预检请求的响应未通过访问控制检查:否 请求中存在“ Access-Control-Allow-Origin”标头 资源。
未捕获(承诺)错误:网络错误 在createError(createError.js:17) 在XMLHttpRequest.handleError(xhr.js:80)
错误图片:https://i.resimyukle.xyz/830y7z.png
addAnswers = async (dispatch, e) => {
e.preventDefault();
const newItem = {
"bookName" : "information",
"price" : "11.11",
"category" :"information",
"author" : "yazar"
}
const response = await axios.post("https://192.168.1.214:5001/api/books",newItem);
console.log(response);
答案 0 :(得分:-2)
你必须这样做
let getRresponse;
axios.post("https://192.168.1.214:5001/api/books",newItem)
.then((response) => {
getRresponse = response; //get your response here like this
});
console.log(getRresponse);
享受!