自上几个小时尝试使用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)的响应
发布评论