Http://blog.chinaunix.net/uid-12348673-id-3335300.html
Set the encoding of the stream to avoid garbled
public static string post (string path,string params) throws exception{HttpURLConnection Httpconn=null; BufferedReader In=null; PrintWriter Out=null; try {URL url=new url (path); Httpconn= (HttpURLConnection) url.openconnection (); Httpconn.setrequestmethod ("POST"); Httpconn.setdoinput (TRUE); Httpconn.setdooutput (TRUE); System.out.print ("params=" +params); Utf-8 printwriter ot = new PrintWriter (New OutputStreamWriter (Httpconn.getoutputstream (), "Utf-8")); OT.PRINTLN (params); Ot.flush (); Out=new PrintWriter (Httpconn.getoutputstream ()); OUT.PRINTLN (params); Out.flush (); Read response if (Httpconn.getresponsecode () ==httpurlconnection.http_ok) {StringBuffer content=new stringbuffer (); String tempstr= ""; Utf-8 in=new BufferedReader (New InputStreamReader (Httpconn.getinputstream (), "Utf-8")); while ((Tempstr=in.readline ())!=null) {content.append (TEMPSTR); } return content.tostring (); }else{throw new Exception ("There is a problem with the request!"); }} catch (IOException e) {E. Printstacktrace (); }finally{in.close ();//Out.close (); Httpconn.disconnect (); } return null;
Java in the post when the Chinese garbled