我正在将对象转换为 base64 编码的字符串并发送到其他服务器,当我从该服务器获得响应时,我将转换该编码的字符串进行解码并再次转换为我的对象,但作为回应他们开火
java.io.StreamCorruptedException:无效的流标头异常。
相同的代码在我的同一方法上正常工作,但在从其他服务器接收时却没有。
这是我的代码
//this is encoding code for request
DemoTest test = new DemoTest();
test.setRollNumber(10);
test.setStdName("Nikhil");
test.setStdClass("BE");
String serializedObject = "";
try {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream so = new ObjectOutputStream(bo);
so.writeObject(test);
so.flush();
serializedObject = bo.toString();
} catch (Exception e) {
System.out.println("encodiiiiing---" + e);
}
// this is decoding code when getting response (from payment gateway server)
String serializedObject = request.getParameter("serializedObject");
try {
byte b[] = serializedObject.getBytes();
ByteArrayInputStream bi = new ByteArrayInputStream(b);
ObjectInputStream si = new ObjectInputStream(bi);
DemoTest test2 = (DemoTest) si.readObject();
System.out
.println("decoded roll number----" + test2.getRollNumber());
System.out.println("decoded name----" + test2.getStdName());
} catch (Exception e) {
System.out.println("decodingggg---" + e);
}