【发布时间】:2017-03-08 00:51:43
【问题描述】:
我在 Angular 控制器中有一个简单的 HTTP post 调用,当我在本地主机上运行它时运行良好,但在将它部署到阶段服务器时出现 403 错误。更具体地说,它只在 Chrome 上出现 403 错误,在 IE 和 FireFox 上运行良好。
这里是JS文件:
var app = angular.module('app', ['ngAnimate', 'ui.bootstrap'], function($locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
});
app.controller('ClearFilesController', ['$rootScope', '$timeout', '$scope', '$http', '$uibModal', '$filter','$window','$location',function($rootScope, $timeout, $scope, $http, $uibModal, $filter,$window,$location) {
$scope.message = "Clear Test Files";
$scope.statusMessage = "Click the button to delete test files in the 'Automation Testing' Collection";
$scope.deleteFiles = function(){
$scope.statusMessage = "Clearing files...";
$http.post('/clearFiles')
.then(function(response){
var status = response.status;
if('200'!=status) {
$scope.statusMessage = "Clearing of files failed.";
} else {
$scope.statusMessage = "Successfully cleared files.";
}
});
};
}]);
这是来自 Chrome 上的开发工具的错误:angular.js:11630 POST https://sample-stageserver.com/clearFiles/403 (Forbidden)
我只在 Chrome 中收到此错误的可能原因是什么?
【问题讨论】:
-
检查 F12 工具中的网络选项卡,看看有什么不同(标题等...)
-
我试过了,除了状态码之外并没有真正看到任何差异。除此之外真的没有太大的不同
-
我发现的唯一区别是 Chrome 在标头中有一个来源和一个主机...主机:sample-stageserver.com 来源:sample-stageserver.com 但 FireFox 和 IE 只有主机。会不会是这个原因?
-
如果这是唯一的区别,那么我会说它一定是造成它的原因。 wiki.mozilla.org/Security/Originen.wikipedia.org/wiki/HTTP_403
标签: javascript angularjs google-chrome post http-status-code-403