问题:
文件上传没有返回值,浏览器console显示Provisional headers are shown
服务端处理数据流方式:
InputStreamReader insr = new InputStreamReader(request.getInputStream(),"utf-8"); // 读取服务器的响应内容并显示 String result = ""; int respInt = insr.read(); while(respInt != -1){ result += (char)respInt; respInt = insr.read(); }
数据流字节少则如上方法可以正常,但是如图片等文件则此方法会出现异常
解决:
服务端处理数据流方式异常,更换服务端数据流处理方式,如:
public static String ReadAsChars2(HttpServletRequest request) { InputStream is = null; StringBuilder sb = new StringBuilder(); try { is = request.getInputStream(); byte[] b = new byte[4096]; for (int n; (n = is.read(b)) != -1; ) { sb.append(new String(b, 0, n)); } } catch (IOException e) { e.printStackTrace(); } finally { if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return sb.toString(); }
来源:51CTO
作者:碧扶摇
链接:https://blog.csdn.net/liuzhen917/article/details/101219025