============ Problem Description ============
The source code is as follows, this time "Zhang San" this character to the web is already two "??", how broken, checked a lot of methods,
such as Urldecoder.decode ("Zhang San", "Utf-8"), or "Zhang San". GetBytes () is not good to use Ah, beg to break
public static String GetXml () throws Exception {
URL posturl = new URL ("Http://10.0.2.2:1234/Android/ANewsManager.aspx?do=add&name= Zhang San");
HttpURLConnection connection = (httpurlconnection) posturl
. OpenConnection ();
Connection.setdoinput (TRUE);
Connection.setrequestmethod ("GET");
Connection.setusecaches (FALSE);
Connection.setinstancefollowredirects (TRUE);
Connection.setrequestproperty ("Content-type", "Text/xml");
Connection.connect ();
BufferedReader reader = new BufferedReader (New InputStreamReader (
Connection.getinputstream (), "Utf-8"));//set encoding, otherwise Chinese garbled
String line = "";
StringBuilder sb = new StringBuilder ();
while (line = Reader.readline ()) = null) {
Sb.append (line);
}
Reader.close ();
Connection.disconnect ();
return sb.tostring ();
}
============ Solution 1============
So is your web side the same utf-8 code you're using?
============ Solution 2============
StringWriter writer = new StringWriter (), Ioutils.copy (Conn.getinputstream (), writer, "UTF-8");
You try this method.
============ Solution 3============
Submit your address directly in the browser Http://10.0.2.2:1234/Android/ANewsManager.aspx?do=add&name= Zhang San
You can see what the code looks like in the address bar, and the test returns are normal or not.
============ Solution 4============
Try to change UTF-8 to GBK.
Android to submit data to the Web, Chinese garbled