IE对http1.1 不支持201状态码

来源:互联网 发布:西恩潘 知乎 编辑:程序博客网 时间:2024/05/22 02:16

最近用spring MVC做一个文件下载程序的时候,发现IE对HttpStatus.CREATED状态的并非完全支持

如:

@RequestMapping(value = "/download", method = RequestMethod.POST )@ResponseBodypublic ResponseEntity<byte[]> download(@RequestParam("fileName") String fName) throws IOException {System.out.println(fName);String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;System.out.println(path);HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);headers.setContentDispositionFormData("attachment", new String(fName.getBytes("GBK"),"ISO8859-1"));File file = new File(path);if(file.exists()){return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers,HttpStatus.CREATED);}headers.setContentDispositionFormData("attachment", "error.txt");return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,HttpStatus.CREATED);}

在IE中并不能下载,而在其他浏览器是可以下载的,但是下面的代码却可以

@RequestMapping(value = "/download", method = RequestMethod.POST )@ResponseBodypublic ResponseEntity<byte[]> download(@RequestParam("fileName") String fName) throws IOException {System.out.println(fName);String path = this.servletContext.getRealPath("/WEB-INF/load") + "\\aaa\\" + fName;System.out.println(path);HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);headers.setContentDispositionFormData("attachment", new String(fName.getBytes("GBK"),"ISO8859-1"));File file = new File(path);if(file.exists()){return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers,HttpStatus.OK);}headers.setContentDispositionFormData("attachment", "error.txt");return new ResponseEntity<byte[]>("发送错误.".getBytes(), headers,HttpStatus.OK);}

所以我认为是IE对201状态码的支持问题,不知道有没有其它解决方法,希望有解决此问题的大师指导。

0 0
原创粉丝点击