【问题标题】:AngularJS CROSS Policy: Access-Control-Allow-Origin errorAngularJS CROSS 策略:Access-Control-Allow-Origin 错误
【发布时间】:2022-12-10 03:47:20
【问题描述】:

当我想用 json 格式做 http post 时,post 方法出错。 $scope.foofnc = () => { $scope.headerDict = { //标题 "访问控制允许来源": "http://localhost:80/", “内容类型”:“应用程序/ json”, “访问控制允许方法”:“POST”, “访问控制公开标头”:“*”, "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" } $http ({ method: 'POST', //发布方法 网址:“https://网址/令牌”, 标头:$范围。 headerDict, 数据:$httpParamSerializerJQLike({ 用户名:$scope.usr, 密码:$scope.passwd }),

    }). then (response => {
        console.log(response.data);
    });

}

【问题讨论】:

    标签: angularjs http-post content-security-policy


    【解决方案1】:

    代码块

    $scope.foofnc = () => {
        $scope.usr="username";
        $scope.passwd="password";
    
    
        $scope.headerDict = {
            "Access-Control-Allow-Origin": "http://localhost:80/",
            "Content-Type": "application/json",
            "Access-Control-Allow-Methods": "POST,",
            "Access-Control-Expose-Headers": "*",
            "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
          }
    
        $http({
            method: 'POST',
            url: "https://url/token",
            headers: $scope.headerDict,
            data: $httpParamSerializerJQLike({
                username: $scope.usr,
                password: $scope.passwd
            }),
    
        }).then(response => {
            console.log(response.data);
        });
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-26
      • 2020-01-18
      • 2015-07-18
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2021-01-13
      相关资源
      最近更新 更多