【发布时间】:2017-04-03 08:10:51
【问题描述】:
此 url 在 AWS API Gateway 中,方法 get 和 stage 部署良好。 我在aws document之后启用了CORS。
这是我启用 CORS 的步骤。
-资源->动作->启用CORS-> 默认设置 -> 启用 CORS 并替换 CORS 标头。 CORS 结果中没有错误日志。
我不是专业的网络开发人员,我的浏览器是 safari。
这是我查询“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” Origin http://example.com 不被 Access-Control-Allow-Origin 所允许。
如果javascript请求或API网关部署有错误?
【问题讨论】:
-
您在 AWS 中设置 CORS 的方式肯定有问题,因为我将 example.com 设置为我本地的虚拟主机。完成后我得到:
XMLHttpRequest cannot load http://my.com/. Redirect from 'http://my.com/' to 'https://my.com/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access. -
非常感谢,我认为您的评论有助于我找到解决问题的方法。
-
我的荣幸。祝你好运!
-
遇到了同样的问题。用这个来解决它 - API gateway CORS lambda
标签: javascript amazon-web-services cors aws-api-gateway