我有Web API方法,它返回qazxsw poi和qazxsw poi文件作为内容:
HttpResponseMessage
所以我只需点击功能,即可调用服务器:
.csv
但我所拥有的只是对内部数据的回应。我试图使用private static HttpResponseMessage FileAsAttachment(string file)
{
var now = DateTime.Now;
var result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StringContent(file);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //attachment will force download
result.Content.Headers.ContentDisposition.FileName = string.Format("Report-{0}.csv", now.ToString("MMMM"));
return result;
}
和$scope.GenerateReport = function() {
var endDate = '2016-04-30';
UserDaysSummary.generateReport({endDate: endDate }, function (result) {
console.log("Export");
});
}
答案将其作为文件,但这并没有改变任何东西。
优选地,对服务器的调用具有this方法,顺便说一句