如何在JavaScript中使用CORS来获取Dialogflow(Api.Ai)的响应

编程入门 行业动态 更新时间:2024-10-09 08:33:55
本文介绍了如何在JavaScript中使用CORS来获取Dialogflow(Api.Ai)的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

自上几个小时尝试使用javascript连接api.ai以来,出现以下错误.

Since last couple of hours when I try to connect api.ai using javascript I get the following error .

无法加载 api.api.ai/v1/query ?v = 20150910 :所请求的资源上没有"Access-Control-Allow-Origin"标头."

"Failed to load api.api.ai/v1/query?v=20150910: No 'Access-Control-Allow-Origin' header is present on the requested resource."

我尝试通过以下方式使用javascript将请求发送到Api.AI:-

I try to send request to Api.AI using javascript by following way:-

const client = new ApiAi.ApiAiClient({ accessToken:"*******************" }); const promise = client.textRequest(query); 承诺 .then(handleResponse) .catch(handleError);

const client = new ApiAi.ApiAiClient({ accessToken: "*******************" }); const promise = client.textRequest(query); promise .then(handleResponse) .catch(handleError);

function handleResponse(serverResponse){}

function handleResponse(serverResponse) {}

推荐答案

我也已经从几个小时开始面对这个问题,看来DialogFlow的人们已经改变了CORS限制.

I too have started facing this issue from few hours, it looks like people at DialogFlow have changed the CORS restrictions.

现在,唯一的解决方案是使用中间的proxy server/cloud function,它将代表浏览器调用api.ai URL并将结果发送回浏览器.

Right now, only solution is to use a middle proxy server / cloud function which will call the api.ai url on behalf of browser and send the result back to browser.

发现了问题并在此处回答.

更多推荐

如何在JavaScript中使用CORS来获取Dialogflow(Api.Ai)的响应

本文发布于:2023-11-28 04:51:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641022.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   JavaScript   CORS   Ai   Api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!