java - how to send an object with URLConnection? -


my goal send object client application server using urlconnection object user :

 public class user {      string nom;      integer id ;      boolean sex;      } 

i don't want send field field object.

you can send object objectoutputstream.
requirement implement java.io.serializable interface.

public class user implements serializable {     ...... } 

now send user-object:

user usr = new user();      url url; httpurlconnection conn; objectoutputstream objout; try {     url = new url("http://192.160.1.1");     conn  = (httpurlconnection) url.getconnection();      conn.setdooutput(true); //this enable writing     conn.setdoinput(true);  //this enable reading      out = new objectoutputstream(conn.getoutputstream());     out.writeobject(usr);     out.close(); } 

now object sent specified url.


Comments