错误:
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
刚才是很奇怪,明明后端代码做了全局跨域处理了,咋还出现跨域呢?
代码:
try { response.reset(); response.setCharacterEncoding("utf-8"); response.setContentType("application/x-msdownload"); response.addHeader("Content-Disposition", "attachment;filename=" + new String(entity.getRealName().getBytes("gb2312"), "ISO8859-1")); input = new BufferedInputStream(ossObject.getObjectContent()); byte[] buffBytes = new byte[1024]; outputStream = response.getOutputStream(); int read = 0; while ((read = input.read(buffBytes)) != -1) { outputStream.write(buffBytes, 0, read); } outputStream.flush(); // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。 ossObject.close(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (outputStream != null) { outputStream.close(); } if (input != null) { input.close(); } } catch (IOException e) { e.printStackTrace(); } }
解决:
原来错误代码是: response.reset(); //这句代码是罪魁祸首,他会清空响应的一些信息,包括全局的跨域配置。
所以解决办法是:
把 response.reset(); 注释掉