我如何将web api中的标题内容返回给AngularJS $ http服务

问题描述 投票:0回答:1

我想从web api返回内容标题

httpResponseMessage.Content = new ByteArrayContent(bytes.ToArray());
httpResponseMessage.Content.Headers.Add("x-filename", fileName);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
httpResponseMessage.Content.Headers.ContentDisposition.FileName = fileName;

我想将此内容标题返回到angularjs $ http服务

$http.get(...).then(function(response){..})

我正在使用AngularJS 1.6,但之前在AngularJS 1.3中,它运行正常,使用$http.get(...).success但是现在它是AngularJS 1.6,它不起作用,我无法在我的项目中使用angularjs 1.3,因为它已经是1.6了,所以请帮助我,如何从webapi获取内容标题数据到angularjs $ http服务

asp.net-web-api2 angularjs-1.6
1个回答
0
投票

这是跨域请求吗?如果是,您是否尝试过公开自定义标题?

httpResponseMessage.Content.Headers.Add(“Access-Control-Expose-Headers”,“x-filename”);

© www.soinside.com 2019 - 2024. All rights reserved.