angularjs - Angular POST 导致源 'http://evil.com/' 是不允许的

标签 angularjs cors

我正在尝试以这种方式发布到 WebApi 后端:

'use strict';
angular.module('auth', []).factory('authService', ['$http', '$q', '$localStorage', function ($http, $q, $localStorage) {

    var serviceBase = 'http://localhost:53432/api/';
    var authServiceFactory = {};

    var authentication = {
        isAuth: false,
        userName: ""
    };

    var saveRegistration = function (registration) {
        return $http.post(serviceBase + 'account/register', registration).then(function (response) {
            return response;
        });

    };

但我收到错误 "message":"The origin 'http://evil.com/' is not allowed."我知道它与 CORS 问题有关,所以我在模块 $sceDelegateProvider 中定义:
$sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'http://localhost:53432' //This is webapi url
        ]);

但这也没有帮助。我应该如何解决这个问题?

在服务器端 CORS 已启用:
 [AllowAnonymous]
 [Route("Register")]
 [HttpPost]
 [EnableCors(origins: "http://localhost:8080", headers: "*", methods: "*")]
 public async Task<IHttpActionResult> Register(RegisterBindingModel register)

最佳答案

这很有趣,但问题是通过关闭浏览器中的 CORS 插件解决的。

从问题中提取的解决方案,作者 andrey.shedko .

关于angularjs - Angular POST 导致源 'http://evil.com/' 是不允许的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41541241/

相关文章:

Flutter Web 集成测试 CORS XMLHttpRequest 错误

javascript - 如何解决 "cannot read property ' push' of undefined"in Firebug Lite?

javascript - 使用 angularjs ng-model 创建 9x9 网格

node.js - 重定向到外部 URL

cors - 上传 Nifi 模板响应 403 错误 + 浏览器记录无效的 CORS 请求

jquery - 如何使跨源资源共享 (CORS) 发布请求正常工作

javascript - Angularjs - 中止/取消运行 $http 调用

javascript - AngularJS TypeError : d is undefined - Firefox, angular-route.min.js:7 Uncaught TypeError: 无法读取未定义的属性 'isArray' - Chrome

java - 如何在 play 2.2.0 Java 中实现 CORS 过滤器?

javascript - Axios 未在请求中发送自定义 header (可能是 CORS 问题)