Api网关不允许访问控制允许来源 [英] Api Gateway cannot allow Access-Control-Allow-Origin

查看:190
本文介绍了Api网关不允许访问控制允许来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此URL在AWS API Gateway中,具有方法get和stage已被良好部署. 然后,我按照

This url is in AWS API Gateway with method get and stage is well deployed. And I enabled CORS following the aws document.

这是我启用CORS的步骤.

Here are my steps to enable CORS.

-资源->操作->启用CORS-> 默认设置->启用CORS并替换CORS标头. CORS结果中没有错误日志.

-Resource->action->enable CORS-> default setting ->enable CORS and replacing the CORS headers. There is no error log in CORS result.

我不是专业的Web开发人员,我的浏览器是野生动物园.
这是我的代码,用于查询"
http://my.com "

I am not a profesional web developer and my browser is safari.
Here is my code to query "http://my.com"

 function request(idex) {
 var xmlHttp = new XMLHttpRequest();
 xmlHttp.onreadystatechange = function() { 
    if (xmlHttp.status == 200)
        callback(xmlHttp.responseText);
 }
 xmlHttp.open("GET", "http://my.com", true);  
 xmlHttp.send(null);}

控制台显示错误: XMLHttpRequest无法加载" http://my.com "来源 http://example.com .

The console print the error : XMLHttpRequest cannot load "http://my.com" Origin http://example.com is not allowed by Access-Control-Allow-Origin.

如果javascript请求或API Gateway部署中存在一些错误?

If there are some mistakes in javascript request or in API Gateway deploy?

推荐答案

在咨询并尝试了每种方法之后,我发现了以下错误.

After consulting and trying each method, I found the error as following.

根据AWS文档,在启用CORS之前,我们无法部署api.在部署之前,必须先设置所有有关标头和CORS的设置. 但是API网关不会阻止此设置,也不会显示任何错误对话框.即使您的设置过程显示成功,API Gateway也不会更改标题.

According to AWS document, we can not deploy our api before enabling CORS. All the settings about the header and CORS must be set before being deployed. But the API Gateway does not block this setting nor does it show any error dialog. API Gateway will not change the header even if your setting process shows success.

这篇关于Api网关不允许访问控制允许来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆