加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:04:54 所属栏目:安全 来源:网络整理
导读:我正试图以这种方式POST到WebApi后端: 'use strict';angular.module('auth',[]).factory('authService',['$http','$q','$localStorage',function ($http,$q,$localStorage) { var serviceBase = 'http://localhost:53432/api/'; var authServiceFactory = {
我正试图以这种方式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写的问题解决了问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读