JAX-RS POST 无法 return 清空 xlsx 作为 mime 类型

JAX-RS POST unable to return empty xlsx as mime type

这是我的 JAX-RS GET 服务的代码

@GET
@Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@Path("/xlsReport")
public Response viewXlsReport(@QueryParam("paymentIds")String paymentIds) throws IOException
{
 List spaymentIds = Arrays.asList(paymentIds.split(","));
 XSSFWorkbook wb = new XSSFWorkbook();
 XSSFSheet s1 = wb.createSheet("Some Details");
 File f = new File("Some Details.xslx");
 FileOutputStream fos = new FileOutStream(f);
 wb.write(fos);
 fos.close();
 return Response.ok((Object)file).build();
}

而POST服务就像

@POST
@Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
@Path("/exportReport")
@Consumes(MediaType.APPLICATION_JSON)
public Response viewXlsReport(String ids) throws IOException
{
 List<string> sIds = new ArrayList<String>();
 StringTokenizer tokens = new StringTokenizer(ids,"&");
 // populate sIds , not used in both GET & POST Version

 XSSFWorkbook wb = new XSSFWorkbook();
 XSSFSheet s1 = wb.createSheet("Some Details");
 File f = new File("Some Details.xslx");
 FileOutputStream fos = new FileOutStream(f);
 wb.write(fos);
 fos.close();
 return Response.ok((Object)file).build();
}

问题

注意事项

  1. 两个代码完全相同,生成空白 xslx文件
  2. 尝试从 java main 生成空白 xlsx 文件,相同的代码,运行良好
  3. 我还检查了 tomcat 上的临时文件,它们对于 GET 和 POST 都没有问题,但是当我从 IE 浏览器下载它们时,我在打开 POST 文件时出错

唯一的区别是 @GET 和 @POST 以及 paymentIds 的解析方式,但是当我们生成空白文件时它们不会被使用(目前,稍后将用于访问数据库并获取一些细节)

真的不确定代码中有什么问题。

问题出在客户端 在 GET 请求中发送正确的 header responseType: 'arraybuffer' ,在 POST 中我没有发送这个 header 因此问题