//前台请求接口
<a href="http://localhost:43640/api/UserInfo/Values/DownloadFile">下载文件</a>
[HttpGet]
public HttpResponseMessage DownloadFile()
{
string fileName = "Word.docx";
string filePath = HttpContext.Current.Server.MapPath("~/") + "Web\\wordtemp\\" + "word.docx";
FileStream stream = new FileStream(filePath, FileMode.Open);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = HttpUtility.UrlEncode(fileName)
};
response.Headers.Add("Access-Control-Expose-Headers", "FileName");
response.Headers.Add("FileName", HttpUtility.UrlEncode(fileName));
return response;
}