我需要使用AngularJS中的HTTP POST方法将JSON发送到Web服务以下载文件。
AngularJS: -
$http
.post(
'url',
'My Json data ')
.success(function(response) {
console.log('file downloading');
})
.error(
function(response) {
console
.log('Error while downloading file');
});
Spring Controller: -
@RequestMapping(value = "/url", method = RequestMethod.POST)
@ResponseBody
public void getfile(@RequestBody List<ABC> abc, HttpServletResponse response)
throws JRException, IOException, SQLException {
//My code here
response.reset();
response.setContentType("application/x-pdf");
response.setHeader("Content-disposition", "attachment; filename=ABC.pdf");
final OutputStream outStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint,outStream);
outStream.flush();
outStream.close();
我必须使用POST请求从angular调用它。怎么实现呢?
修改 我能够通过引用this线程来满足要求。