【问题标题】:Is Excel clearing our http request authorization header attribute?Excel 是否清除了我们的 http 请求授权标头属性?
【发布时间】:2019-04-17 23:44:21
【问题描述】:

我们正在尝试让我们的 Office Excel 加载项联系我们自己的一种 Web API 服务,以便它可以从中发送和接收数据。对于要授权的请求,我们必须填写 Authorization 标头属性。这就是我们处理请求的方式,它在我们所有的普通 Web 应用程序中都运行良好。

this.LoginAuth = function (authString) {    
    $http.defaults.headers.common.Authorization = 'Basic ' + authString;

    return $http({
        url: MainFactory.GetWebAPILocation() + '/API/User/AddInLoginAuth',
        dataType: 'json',
        method: 'POST',
        data: {},
        headers: {
            "Content-Type": "application/json"
        }
    });
}

但是,当通过加载项发出请求时,授权属性已被清除,导致我们的请求失败。这是由 Excel 完成的属性清除吗?如果是这样,有什么方法可以阻止它?

【问题讨论】:

  • 您可以尝试将标头添加到配置对象,即标头:{ "Content-Type": "application/json" , "Authorization" = "Basic +authstring" }
  • 不幸的是,如果我们这样做,同样的事情会发生;授权标头被清除。
  • AngularJS $http 服务忽略了dataType: 'json' 属性设置。并且 Content-Type 标头是不必要的,因为这是自动默认值。

标签: angularjs asp.net-web-api excel-addins


【解决方案1】:

原来这是我们的 Web API 服务中的 CORS 问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 2017-07-13
    • 2019-01-10
    • 2014-06-16
    • 1970-01-01
    相关资源
    最近更新 更多