【发布时间】:2016-06-15 17:33:14
【问题描述】:
我认为 TFS RESTful api 有一个错误。我正在尝试使用 Angular Web 应用程序访问它。我们的 TFS 服务器是公司内部的。这是我的代码:
var path = 'http://tfs.mycompany.com/tfs/mycompany/_apis/wit/queries?$depth=1&$expand=all&api-version=2.2';
var config = { withCredentials: true };
$http.get(path, config)
.then(function (response) {
$scope.resultList = response.data.d.results || [ response.data.d ];
$scope.message = 'Found ' + $scope.resultList.length + ' item' + ($scope.resultList.length == 1 ? '':'s');
}, function (response) {
$scope.resultList = [];
$scope.message = 'Error ' + response.status + ' ' + JSON.stringify(response.data);
});
请求到达服务器,服务器以 OK 200 响应。但是,浏览器 (Chrome) 阻止了数据,并告诉我:
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header
when the credentials flag is true. Origin 'http://localhost' is therefore
not allowed access. The credentials mode of an XMLHttpRequest is controlled
by the withCredentials attribute.
请求头有Origin:http://localhost
响应头有Access-Control-Allow-Origin:*
我有什么方法可以告诉 TFS 在Access-Control-Allow-Origin 中不返回 *?这似乎是 TFS 中的一个严重错误,它使 RESTful api 对于 Web 应用程序几乎毫无用处!
【问题讨论】: