【发布时间】:2020-12-29 23:45:16
【问题描述】:
我想使用 Angular 在 excel 文件中下载模型,这是我的服务代码的功能:
getExcelReport(data: myModel[]): Observable<Blob> {
let params = new HttpParams()
.set('myParam', JSON.stringify(data));
return this.Http.get(this.url + '/MyController/GetExcelReport', { params: params, observe: "body", responseType: "blob" });
当我调用它时,我得到一个错误:415(不支持的媒体类型)。 我知道要使用的正确语法吗? 谢谢
【问题讨论】:
-
听起来像是服务器端问题?
-
这是我在服务器端控制器中的内容` [HttpGet] [Route("GetExcelReport")] public async Task
GetExcelReport([FromBody] IList myModel)` -
收到文件后你真正想要什么..?您是否希望用户简单地下载它?如果是这样,一个 window.open 可能会容易得多。如果您需要更多(例如在请求中设置身份验证标头),也许这会有所帮助:stackoverflow.com/questions/58335807/…
标签: angular typescript