【发布时间】:2016-05-13 13:03:18
【问题描述】:
我有一个从 web api 返回文件的方法
public static HttpResponseMessage FileAsFileAttachment(byte[] bytes, string filename)
{
var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(bytes) };
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename};
return result;
}
如何从响应中读取 Content-Disposition 标头?
this.httpClient.fetch(`/company/get-asic-fee-autocomplete`).then(data=> { console.log(data.headers.get("Content-Disposition "))});
此标头始终为空
如何在 aurelia fetch-client 中获取文件名并显示所有标题???
【问题讨论】:
-
在我的情况下 console.log(data.headers) 看起来像 gyazo.com/1d32a4e9226bac151102649d607716fa
-
我看到你的代码
data.headers.get("Content-Disposition ")中有一个空格。试试data.headers.get("content-disposition") -
没关系。此值始终为空。也许 aurelia fetch-client 不支持某些标头。
-
如果您尝试获取
content-type而不是content-disposition,是否可行? -
是的。内容类型工作正常。
标签: aurelia aurelia-fetch-client