【发布时间】:2021-01-16 23:54:48
【问题描述】:
当我向这个特定句柄发送请求时,使用以下代码在网页中呈现文件
[HttpGet]
[Route("learning/{pdfid}")]
public HttpResponseMessage RenderProjectDocumentById(string pdfid)
{
var doc = _projectDocumentService.GetProjectDocument(pdfid);
var contentType = "application/octet-stream";
var res = Request.CreateResponse(HttpStatusCode.OK);
res.Content = new StreamContent(new MemoryStream(doc.BinaryData));
res.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
res.Content.Headers.ContentDisposition.FileName = doc.name + "." + doc.doc;
res.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
return res;
}
如果我在网络浏览器中输入这个
http://localhost:49454/learning/5711130b9aa56d03a0e2f26f
它会在自己的网页中下载文件
但如果我从 WPF 应用程序发送相同的请求,如下所示
var response = await Client.GetAsync("/learning/" + doc.Id);
如何让它从 html 页面下载?
【问题讨论】:
标签: c# wpf asp.net-web-api asp.net-web-api2