【发布时间】:2016-05-05 08:43:18
【问题描述】:
我创建了一个应用程序,该应用程序正在访问/获取来自不同域(例如 domain_name)的 mongo/node+express 的数据。
get函数的代码是:
var request = $http({
method: 'GET',
url: 'https://domain_name.users.io/categories/list',
withCredentials: true /* to get the Cookie value generated at server-side */
});
在快递方面,为了避免 CORS 问题,添加了以下代码:
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods","GET,PUT,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Credentials", "true");
对于上述情况,我收到以下错误:
XMLHttpRequest cannot load https://domain_name.users.io/data/list. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access.
我已经检查了 API“https://domain_name.users.io/data/list”并且没有问题,因为我可以看到数据(在浏览器上点击时)。
有人可以帮我做同样的事情吗
【问题讨论】:
-
您是否通过本地主机访问domain_name.users.io/categories/list?如果你这样做,我认为你可以使用 httpclient 访问domain_name.users.io/categories/list
标签: angularjs node.js mongodb express ionic-framework