首页 > 解决方案 > 无法与 Rasa 服务器对话 - POST 时出现 CORS 错误

问题描述

我已经在 AWS Ubuntu 服务器上成功部署了 Rasa 服务器,它在终端中运行良好,但我无法通过 fetch() 从 POST 访问。

我运行这个命令:

rasa run --enable-api --cors *.*

它回应:

Starting Rasa server on http://localhost:5005
Rasa Sever is up and running.

它在浏览器(即 xxx.xxx.xxx:5005)中响应“来自 Rasa 的 Hello:2.8.3”,因此它已连接,但是当我尝试通过 fetch() POST 到 if 时,它给了我一个 CORS 错误:

const url = 'http://xxx.xxx.xxx.xxx:5005/model/parse';
fetch(url, { method: 'POST',
     body: "{text:'Hello'}"})
    .then(res => { console.log(res); res.json()})
    .then(res => console.log(res))

标签: ubuntunlpcorsrasarasa-core

解决方案


The url you added in your code is incorrect if you want a response.

const url = "HTTP://ip:5005/webhooks/rest/webhook";
fetch(url, { method: "POST",
body: "{sender: 'me', message: 'Hi'}"
})

If you still have any doubts feel free to ask.


推荐阅读