gpt4 book ai didi

angularjs - $http : how to get filename of headers from WebApi with CORS

转载 作者:行者123 更新时间:2023-12-03 04:44:57 26 4
gpt4 key购买 nike

我遇到问题,无法从 $http 响应的 header 获取文件名

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: attachment; filename=Order-414.pdf
Date: Wed, 11 Feb 2015 05:32:25 GMT

我只想在下载时获取文件名(Order-414.pdf)作为pdf名称。但在此代码块中:

   $http.get(httpPath, { responseType: 'arraybuffer' })
.success(function (data, status, headers) {
debugger;
// just return content-type
var header = headers();

header 对象仅包含内容类型。

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);
}

但是还是不行。请帮我。提前致谢。

最佳答案

我想您需要将 Content-Disposition 而不是 filename 添加到 Access-Control-Expose-Headers

cors.ExposedHeaders.Add("Content-Disposition");

关于angularjs - $http : how to get filename of headers from WebApi with CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28447391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com