gpt4 book ai didi

angularjs - 无法从http.get header 获取内容处置?

转载 作者:行者123 更新时间:2023-12-04 07:34:52 25 4
gpt4 key购买 nike

我正在尝试使用Web API + Angularjs下载文件,并且工作正常,但是我正在从Web API的 header 中发送“content-disposition”,但无法在响应 header 中访问它。

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

在标题中,我得到以下值,但无法获得内容处置。请纠正我我错了吗?

enter image description here

最佳答案

我猜您正在尝试将文件托管在服务器上时从localhost进行访问,在这种情况下,请您的服务器团队允许Access-Control-Expose-Headers(‘Content-Disposition’)。使用此 header ,您可以跨域访问自定义 header ,例如COntent-Disposition

关于angularjs - 无法从http.get header 获取内容处置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36174994/

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