客户端:
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/octet-stream");
//发送数据
HashMap map=new HashMap();
map.put("test",test);
ObjectOutputStream objOutStream = new ObjectOutputStream(con.getOutputStream());
objOutStream.writeObject(updatePPPHashMap);
objOutStream.flush();
objOutStream.close();
//读取数据
ObjectInputStream objInStream = new ObjectInputStream(con.getInputStream());
String message = (String) objInStream.readObject();
if (message.equals("SUCCESS")) {
JOptionPane.showMessageDialog(this, "提交成功!");
} else {
JOptionPane.showMessageDialog(this, "提交失败!");
}
objInStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
注意:
如果客户端只有输出流,没有输入流,将无法触发连接,原因不详
服务端: