我正试图以这种方式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)