我尝试通过 angular 2 typescript 客户端下载文件。Swagger UI 中生成的链接可以正常工作,但生成的 typescript 客户端不能。
控制器如下所示:
[HttpGet("export")]
[SwaggerResponse((int) HttpStatusCode.OK, Type = typeof(FileContentResult))]
[ProducesResponseType(typeof(FileResult), (int) HttpStatusCode.OK)]
[Produces("text/csv")]
public virtual FileResult Export(int Id, string fileType, CsvFormat format, bool includeHeader)
{
.
.
.
FileStreamResult file = new FileStreamResult(s, "text/csv");
file.FileDownloadName = ts.Name + "." + fileType;
return file;
}
生成的打字稿客户端如下所示。如您所见, responseText 已设置但从未返回。我错过了什么?
protected processRestTimeSeriesExportGet(response: Response): Observable<void> {
const status = response.status;
if (status === 200) {
const responseText = response.text();
return Observable.of<void>(<any>null);
} else if (status !== 200 && status !== 204) {
const responseText = response.text();
return throwException("An unexpected server error occurred.", status, responseText);
}
return Observable.of<void>(<any>null);
}
此致