我正试图以这种方式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;
});
};
Run Code Online (Sandbox Code Playgroud)
但我得到错误"message":"The origin 'http://evil.com/' is not allowed."
我明白这与CORS问题有关,所以我在模块中定义$sceDelegateProvider:
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://localhost:53432' //This is webapi url
]);
Run Code Online (Sandbox Code Playgroud)
但这也没有帮助.我该怎么解决这个问题?
在服务器端已启用CORS:
[AllowAnonymous]
[Route("Register")]
[HttpPost]
[EnableCors(origins: "http://localhost:8080", headers: "*", methods: "*")]
public async Task<IHttpActionResult> Register(RegisterBindingModel register)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5435 次 |
| 最近记录: |