transformResponse headers参数($ resource)中缺少自定义响应的标头

时间:2015-10-21 10:48:05

标签: angularjs ngresource

我已经为API端点定义$resource,该端点返回包含多个headers的响应,但在transformResponse配置函数中,{{1}中缺少大多数标头函数参数。

我该如何解决?

API的响应标头

headersGetter

HTTP/1.1 201 Created Server: Apache-Coyote/1.1 x-content-type-options: nosniff x-xss-protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 x-frame-options: DENY Access-Control-Allow-Origin: http://localhost:9000 access-control-allow-methods: POST, PUT, GET, DELETE, OPTIONS access-control-allow-headers: Content-Type Access-Control-Allow-Credentials: true Content-Disposition: attachment; filename="testCall.pcap" FileName: testCall.pcap Content-Type: application/pcap 标题

transformResponse
Pragma: no-cache
Content-Type: application/pcap
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: 0

1 个答案:

答案 0 :(得分:12)

假设您正在进行CORS调用,响应标头并非全部暴露。服务器端需要在CORS过滤器中添加响应头“Access-Control-Expose-Headers”。

e.g。要通过CORS调用读取名为“X-MY-HEADER1”和“X-MY-HEADER2”的自定义响应标头,服务器添加标头

Access-Control-Expose-Headers: "X-MY-HEADER1, X-MY-HEADER2"

@nancoder在https://stackoverflow.com/a/23726352/4684232

查看答案