gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:55:13 24 4
gpt4 key购买 nike

我正在尝试以这种方式发布到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com