angularjs – 角度POST导致原点’http://evil.com/’是不允许的

前端之家收集整理的这篇文章主要介绍了angularjs – 角度POST导致原点’http://evil.com/’是不允许的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正试图以这种方式POST到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;
        });

    };

但我得到错误“消息”:“原产地’http://evil.com/’是不允许的.”
我知道它与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相关文章