angularjs – $http:如何使用CORS从WebApi获取头文件名
发布时间:2020-12-17 07:08:43 所属栏目:安全 来源:网络整理
导读:我遇到问题,我无法从$http响应的标头中获取文件名 HTTP/1.1 200 OK Content-Length: 121257 Content-Type: application/pdf Server: Microsoft-HTTPAPI/2.0 Access-Control-Allow-Origin: * Access-Control-Expose-Headers: * Content-Disposition: attachme
|
我遇到问题,我无法从$http响应的标头中获取文件名
我只想在下载时获取文件名(Order-414.pdf)作为pdf名称.但是在这个代码块中: $http.get(httpPath,{ responseType: 'arraybuffer' })
.success(function (data,status,headers) {
debugger;
// just return content-type
var header = headers();
header对象只包含content-type. Object {content-type: "application/pdf"}
我在某处读到我们需要为WebAPI配置CORS: private static void RegisterCorsConfig(HttpConfiguration config)
{
var cors = new EnableCorsAttribute("*","*","*");
//var cors = new EnableCorsAttribute("*","DataServiceVersion,MaxDataServiceVersion");
//cors.ExposedHeaders.Add("*");
//cors.ExposedHeaders.Add("filename");
config.EnableCors(cors);
}
但它仍然无效.请帮我. 解决方法
我想你需要在Access-Control-Expose-Headers中添加Content-Disposition而不是filename
cors.ExposedHeaders.Add("Content-Disposition");
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
