小编use*_*049的帖子

HttpResponseMessage内容不会显示PDF

我创建了一个Web Api,它返回一个HttpResponseMessage,其中的内容设置为PDF文件.如果我直接调用Web Api,它可以很好地工作,并且PDF将在浏览器中呈现.

response.Content = new StreamContent(new FileStream(pdfLocation, FileMode.Open, FileAccess.Read));
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        response.Headers.ConnectionClose = true;
        return response;
Run Code Online (Sandbox Code Playgroud)

我有一个想要联系Web Api的MVC客户端,请求Pdf文件然后以与上面相同的方式将其呈现给用户.

不幸的是,我不确定问题出在哪里,但即使我设置了内容类型:

response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
Run Code Online (Sandbox Code Playgroud)

当我点击调用web api的链接时,我得到了HttpResponseMessage的文本呈现.

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Connection: close Content-Disposition: attachment Content-Type: application/pdf }
Run Code Online (Sandbox Code Playgroud)

我认为客户端应用程序缺少一些设置,允许它像我的Web Api那样呈现PDF ...

任何帮助,将不胜感激.谢谢

pdf asp.net-mvc content-type asp.net-web-api

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-web-api ×1

content-type ×1

pdf ×1