reactjs - 将 RASA POST webhook API 连接到 React Web UI 时出错
问题描述
这是用于连接 RASA webhook API 的反应服务器端代码。我的状态为 0。但在 RASA 框架中正常工作并为此请求发送答案。问题是我无法获取 API 调用的重新运行答案。
从“反应”导入反应,{组件}
export const rasaAPI = async function RASA(name, dialogue) {
// POST request using fetch with error handling
await fetch('http://192.168.8.100:5005/webhooks/rest/webhook', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'charset':'UTF-8'
},
body: JSON.stringify({ "sender": name, "message": dialogue }),
})
.then(function(response) {
if(response.ok) {
return response.blob();
}
throw new Error(response.status);
})
.then(response => response.json())
.then(result => {
console.log('Success:', result);
})
.catch(error => {
console.error('Error:', error);
});
}
这是 API 请求的控制台错误。
解决方案
正确答案 :
React 应用程序:从 'react' 导入 React,{ Component }
export const rasaAPI = async function RASA(name, dialogue) {
// POST request using fetch with error handling
await fetch('/webhook', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'charset':'UTF-8',
},
credentials: "same-origin",
body: JSON.stringify({ "sender": name, "message": dialogue }),
}).then(response => {
return response.json();
}).then(massage => {
console.log(massage);
});
}
将 URL 添加到 package.json 文件中。
推荐阅读
- c++ - c++ 如何处理 int 和 unsigned int 之间的算术运算?
- cassandra - Cassandra:在一致性 LOCAL_QUORUM 的简单写查询期间超时
- android - CameraX:ImageAnalysis 的输出看起来已损坏/分散
- flutter - 当我在标签之间导航时自动注销问题(Firebase Auth rest API)
- ios - MDCChipView 设置图片大小
- reactjs - React material-ui中Tab、TabContext、Tablist、TabPanel的区别
- node.js - 如何在不删除服务器生成的文件的情况下部署 dist 文件夹
- python - 逐列检查数组中的元素是否存在于另一个数组中
- python - Mac 上 CPLEX Python API 安装大问题 CpoException
- amazon-web-services - 为什么我不能通过 EC2 (AWS) 访问我托管的 Flask webApp