invalid stream header问题的解决 invalid stream header异常
程序员文章站
2024-03-25 18:17:10
...
今天调试一个http接口,调用端代码如下
URL url = new URL("http://www.AAA.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
Map map = new HashMap();
map.put("type", "ttt");
out.writeObject(map);
out.flush();
out.close();
服务端代码如下:
InputStream is = ####;
ObjectInputStream ois = new ObjectInputStream(is);//异常产生出
Map map = (Map) ois.readObject();
ois.close();
is.close();
服务端在异常产生出报invalid stream header异常,跟踪代码发现是ObjectInputStream(InputStream in)方法中会检查stream的头信息readStreamHeader(),头信息异常导致invalid stream header产生,检查调用端的代码发现没有设置Content-Type,因为是用序列号的二进制流,类型为application/xml,加上一句connection.setRequestProperty("Content-Type", "application/xml"),问题解决
URL url = new URL("http://www.AAA.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
Map map = new HashMap();
map.put("type", "ttt");
out.writeObject(map);
out.flush();
out.close();
服务端代码如下:
InputStream is = ####;
ObjectInputStream ois = new ObjectInputStream(is);//异常产生出
Map map = (Map) ois.readObject();
ois.close();
is.close();
服务端在异常产生出报invalid stream header异常,跟踪代码发现是ObjectInputStream(InputStream in)方法中会检查stream的头信息readStreamHeader(),头信息异常导致invalid stream header产生,检查调用端的代码发现没有设置Content-Type,因为是用序列号的二进制流,类型为application/xml,加上一句connection.setRequestProperty("Content-Type", "application/xml"),问题解决
推荐阅读
-
invalid stream header问题的解决 invalid stream header异常
-
Chrome浏览器安装插件时出现CRX-HEADER-INVALID的解决方法
-
java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
-
java.io.StreamCorruptedException: invalid stream header: EFBFBDEF
-
node vue 开发环境部署时,外部访问页面出现: Invalid Host header 服务器域名访问出现的问题
-
java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)异常解决方法
-
invalid stream header: EFBFBDEF 问题解决
-
解决vue项目中出现Invalid Host header的问题
-
解决webpack "Invalid Host header"问题
-
node vue 开发环境部署时,外部访问页面出现: Invalid Host header 服务器域名访问出现的问题