Man*_*ngh 8 http-headers angularjs asp.net-web-api2
我正在尝试使用Web API + Angularjs下载文件并且它工作正常,但我在Web API的标头中发送'content-disposition'但我无法在响应标头中访问它.
的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;
}
Run Code Online (Sandbox Code Playgroud)
客户端(AngularJs):
$http.get(url)success(function (data, status, headers) {
var header= headers();
})
Run Code Online (Sandbox Code Playgroud)
在标题中我得到以下值但我无法获得内容处置.请纠正我错在哪里?
我猜你试图在文件托管在服务器上时从localhost点击它,在这种情况下要求你的服务器团队允许,访问控制 - 暴露 - 标题('内容 - 处置').使用此标头,您可以通过跨域访问自定义标头,如COntent-Disposition
归档时间: |
|
查看次数: |
4265 次 |
最近记录: |