我正在使用Web API + Angularjs下载文件,目前一切正常。但是,我在Web API的标头中发送了“content-disposition”,但无法在响应标头中访问它。
WebAPI:![enter image description here](https://istack.dev59.com/HG75b.webp)
WebAPI:
[HttpGet]
[AllowCrossSiteJson]
public HttpResponseMessage GetAcquisitionsTemplate()
{
var docContent = _d.FirstOrDefault();
Stream stream = new MemoryStream(docContent.Content);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
string contentDisposition = string.Concat("attachment; filename=", docContent.Name.Replace(" ", String.Empty), "." + docContent.Extension);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(contentDisposition);
return result;
}
客户端(AngularJs):
$http.get(url)success(function (data, status, headers) {
var header= headers();
})
在头部我得到了以下数值,但是我不能获取content-disposition。请纠正我错在哪里?
![enter image description here](https://istack.dev59.com/HG75b.webp)