angularjs – transformResponse headers参数($resource)中缺少
发布时间:2020-12-17 07:18:31 所属栏目:安全 来源:网络整理
导读:我已经为API端点定义了一个$资源,该端点返回包含多个头的响应,但在 transformResponse 配置函数中,headersGetter函数参数中缺少大多数头. 我该如何解决? API的响应标头 HTTP/1.1 201 CreatedServer: Apache-Coyote/1.1x-content-type-options: nosniffx-xss
我已经为API端点定义了一个$资源,该端点返回包含多个头的响应,但在
transformResponse 配置函数中,headersGetter函数参数中缺少大多数头.
我该如何解决? API的响应标头 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,must-revalidate Expires: 0 app.factory("MyService",function ($resource,ENV,_) { return { testCall: $resource(ENV.apiEndpoint + "/test-call",{},{ launch: { method: 'POST',isArray: false,headers:{'Accept':'application/octet-stream'},responseType: 'blob',cache: false,transformResponse: function(data,headers){ var filename = headers('Content-Disposition'); //headers('FileName') var contentType = headers('Content-Type'); var file = new Blob([data],{ type: contentType }); var fileURL = URL.createObjectURL(file); var a = document.createElement('a'); a.href = fileURL; a.target = '_blank'; a.download = filename; document.body.appendChild(a); a.click(); } } }),searchOptions: $resource(ENV.apiEndpoint + "//search-options") }; });
假设您正在进行CORS调用,响应标头并非全部暴露.服务器端需要在CORS过滤器中添加响应头“Access-Control-Expose-Headers”.
例如要使用CORS调用读取名为“X-MY-HEADER1”和“X-MY-HEADER2”的自定义响应标头,请添加标头 访问控制 – 暴露 – 标题:“X-MY-HEADER1,X-MY-HEADER2” 请参阅@nancoder在https://stackoverflow.com/a/23726352/4684232的答案 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |