Android to submit data to the Web, Chinese garbled

Source: Internet
Author: User

============ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.