0
对预检请求的响应未通过访问控制检查:请求的资源上没有“Access-Control-Allow-Origin”标头。头还是什么?
我的代码
.factory('AuthenticationService',
['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
function (Base64, $http, $cookieStore, $rootScope, $timeout) {
var service = {};
service.Login = function (UserName, Password, callback) {
/* Dummy authentication for testing, uses $timeout to simulate api call
----------------------------------------------
$timeout(function() {
var response = { success: UserName === 'test' && Password === 'test' };
if (!response.success) {
response.message = 'UserName or Password is incorrect';
}
callback(response);
}, 1000);
*/
/* Use this for real authentication
----------------------------------------------*/
$http({
method: 'POST',
url: 'http://216.0.1.209/AuthenticateUser',
data: {
UserName: 'UserName',
Password: 'Password'
},
headers: {
'content-type: multipart/form-data; boundary=---011000010111000001101001'
}
}).then(function(response) {
console.log(response)
});
};
service.SetCredentials = function (UserName, Password) {
var authdata = Base64.encode(UserName + ':' + Password);
$rootScope.globals = {
currentUser: {
UserName: UserName,
authdata: authdata
}
};
$http.defaults.headers.common['Authorization'] = 'Basic' + authdata; // jshint ignore:line
$cookieStore.put('globals', $rootScope.globals);
};
service.ClearCredentials = function() {
$rootScope.globals = {};
$cookieStore.remove('globals');
$http.defaults.headers.common.Authorization = 'Basic';
};
return service;
}])
测试在Chrome,火狐和IE,给予同样的结果“否‘访问控制允许来源’标头出现在所请求的资源。” ..
温暖的regars ..感谢您的任何帮助或建议