1
votes

I have a simple HTTP post call in an angular controller that works fine when I run it on my local host, but gets a 403 error when it is deployed to a stage server. More specifically it only gets the 403 error on Chrome, it works fine on IE and FireFox.

Here is the JS file:

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.";
            }
        });

};

}]);

Here is the error from the dev tools on Chrome: angular.js:11630 POST https://sample-stageserver.com/clearFiles/ 403 (Forbidden)

What would be a possible reason why I am only getting this error in Chrome?

1
Check the Network tab in F12 tools to see what is different (headers, etc...) - Dan Beaulieu
I tried that and didn't really see any differences other than the status code obviously. Other than that there really wasn't much different - Developer Guy
The only difference I have found is Chrome has an origin and a host in the headers...Host:sample-stageserver.com Origin:sample-stageserver.com but FireFox and IE only have host. Could that be causing it? - Developer Guy
If it's the only difference, then I'd say it must be causing it. wiki.mozilla.org/Security/Origin en.wikipedia.org/wiki/HTTP_403 - Dan Beaulieu

1 Answers

0
votes

I can add comment - so u can try postman for the testing your problem. And try use basic $http like as an example - Angular $http doc (not the shorthand).