大佬教程收集整理的这篇文章主要介绍了angularjs – transformResponse headers参数($resource)中缺少自定义响应的标头,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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调用读取名为“X-MY-HEADER1”和“X-MY-HEADER2”的自定义响应标头,请添加标头
访问控制 – 暴露 – 标题:“X-MY-HEADER1,X-MY-HEADER2”
请参阅@nancoder在https://stackoverflow.com/a/23726352/4684232的答案
以上是大佬教程为你收集整理的angularjs – transformResponse headers参数($resource)中缺少自定义响应的标头全部内容,希望文章能够帮你解决angularjs – transformResponse headers参数($resource)中缺少自定义响应的标头所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。