我认为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应用程序几乎无用!
答案 0 :(得分:0)
您可以查看下面的Cross-origin resource sharing (CORS)示例,在代码中添加授权:
var a = "26/12/1987";
var b = a.replace(/\//g,"-");
console.log(b);
另外,请检查此案例以查看它是否有用: