我在发送邮件时收到此错误。你知道我必须做什么吗?登录 WinApi C#
XMLHttpRequest cannot load http://localhost:56305/Token. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:64757' is therefore not allowed access. The response had HTTP status code 400.
我的代码
//linki
$scope.addLink = "http://localhost:56305/Token";
$scope.addData = function () {
if ($scope.password != "" && $scope.email) {
$http({
method: "POST",
url: $scope.addLink,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
headers: {'X-Requested-With' :'XMLHttpRequest'},
data: { grant_type: 'password', username: $scope.email, Password: $scope.password }
}).then(function mySucces(response) {
$scope.stateHideError = true;
$scope.stateHideSuccess = false;
Authorization.go('carInsurance');
}, function myError(response) {
$scope.stateHideError = false;
$scope.stateHideSuccess = true;
$scope.error = "Wystąpił błąd - Problem z wysłaniem parametrów";
});
}
else {
$scope.stateHideError = false;
$scope.stateHideSuccess = true;
$scope.error = "Wystąpił błąd - nie podałeś wszystkich wymaganych wartości.";
}
};
我想发送这样的内容
我将其添加到 WinApi C#
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
</customHeaders>
</httpProtocol>
现在我遇到了这个错误
XMLHttpRequest cannot load http://localhost:56305/Token. Response for preflight has invalid HTTP status code 400
最佳答案
这是一篇示例文章,如何启用 CORS http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
您的服务器拒绝来自 js 应用程序的请求,因为您的 js 是从不同的 URL 加载的
关于c# - 使用 Angular 登录 WinApi C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39489689/