【问题标题】:$http.post send Authorization Header$http.post 发送授权标头
【发布时间】:2015-05-15 00:03:39
【问题描述】:

我正在尝试通过 $http.post 调用将授权标头传递给 .NET Web API 服务。

如果我使用这个:

$http.post(urls.getEmployeeInfo,
        {
            withCredentials: true,
            headers:{ 'Authorization':  'Basic ' + btoa(username + ":" + password)}
        }
    );

授权标头未发送到我的服务。

以下作品:

$http({
            url: urls.getEmployeeInfo,
            method: "POST",
            withCredentials: true,
            headers: {
                'Authorization': 'Basic ' + btoa(username + ":" + password)
            }
        });

为什么 $http.post 不发送 Authorization Header ?

谢谢

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    $http 只接受一个参数:config [documentation]

    $http.post 接受三个参数:urldata,(和一个可选参数)config [documentation]

    所以如果你想传递配置选项,比如标题,你需要将它们作为第三个参数发送,而不是第二个:

    $http.post(urls.getEmployeeInfo, postData,
        {
            withCredentials: true,
            headers:{ 'Authorization':  'Basic ' + btoa(username + ":" + password)}
        }
    );
    

    【讨论】:

      猜你喜欢
      • 2019-01-29
      • 2020-05-22
      • 1970-01-01
      • 2020-03-28
      • 2017-12-04
      • 1970-01-01
      • 2017-11-23
      • 2018-07-12
      • 2018-12-28
      相关资源
      最近更新 更多