【问题标题】:How to get the complete response headers from angular resource如何从角度资源中获取完整的响应标头
【发布时间】:2015-03-30 16:47:23
【问题描述】:

我正在发送一个带有 Angular $resource 的请求:

myResource.get({ foo: bar }, function success(data, headers) {
            console.log("data:", data); // Prints data
            console.log("headers:", headers()); // Prints only few headers
        }, function failure(response, status) {
            // Handling failure here...
        })

但我只得到几个标题:

{content-type: "application/json", cache-control: "no-cache, max-age=604800", expires: "Mon, 06 Apr 2015 16:21:17 GMT"}

当我想捕获标题“X-Token”时(如果我在浏览器控制台中检查就会收到)

知道从 Angular 和 $resource 接收完整的标头列表吗?

【问题讨论】:

    标签: angularjs http-headers angular-resource


    【解决方案1】:

    出于安全原因,默认情况下不公开某些响应标头。因此,您需要在服务器上使用Access-Control-Expose-Headers,并添加您要返回的额外响应头。

    Access-Control-Expose-Headers: X-Token, header-a
    

    【讨论】:

      猜你喜欢
      • 2021-10-21
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-08-21
      • 2017-06-23
      • 2018-08-08
      • 2019-03-14
      • 1970-01-01
      相关资源
      最近更新 更多