【问题标题】:Angular http post returning a 403 error on server only in ChromeAngular http post 仅在 Chrome 中在服务器上返回 403 错误
【发布时间】: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


【解决方案1】:

我可以添加评论 - 所以你可以尝试邮递员来测试你的问题。 并尝试使用基本的 $http 作为示例 - Angular $http doc(不是简写)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 2021-12-18
    • 2021-01-22
    相关资源
    最近更新 更多