如何从角度资源获取完整的响应头

tez*_*zqa 5 http-headers angularjs angular-resource

我正在发送一个Angular $资源的请求:

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...
        })
Run Code Online (Sandbox Code Playgroud)

但我只得到几个标题:

{content-type: "application/json", cache-control: "no-cache, max-age=604800", expires: "Mon, 06 Apr 2015 16:21:17 GMT"}
Run Code Online (Sandbox Code Playgroud)

当我想要抓住标题"X-Token"(如果我在浏览器控制台中检查就会收到)

有没有想过从Angular和$ resource接收完整的标题列表?

Muh*_*eda 3

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

Access-Control-Expose-Headers: X-Token, header-a
Run Code Online (Sandbox Code Playgroud)