When using Xutils, the POST request is passed in Chinese to the server side MySQL database is garbled.
This question puzzled me for a long time, also took a lot of detours. After constant exploration, we finally found a solution to the problem.
First: Check your MySQL code. Cmd->mysql–uroot–p---Enter your own MySQL password--input showvariables like ' character% '; (If you install MySQL by default, there will be a lot of latin1, And not all of my below utf-8, this is because MySQL default encoding is latin1), if all is Latin1 words, want to not appear Chinese garbled words, will change utf-8.
Second: Change Latin1 to Utf-8. Locate the My.ini file under the path where MySQL is installed. Open this file.
Add Default-character-set=utf8 to the next line in: [Client]
[MySQL] join Default-character-set=utf8 next line
[Mysqld] Next line to join Character-set-server=utf8 (note here the older version of MySQL join Default-character-set=utf8 is OK, but 5.5 will not be able to restart MySQL will be an error)
Find # Thedefault Character set that would be used when a new schema or table is
# created and no character set is defined
character-set-server= Latin1 changed to Character-set-server=utf8.
This allows the Latin1 to be utf-8. Restart MySQL (right-click My Computer, manage services and applications, find MySQL restart) and you will find it when you repeat the first step. Most Latin1 have become utf-8. Unfortunately, there is one (character-set-server) or for Latin1, this is because when the installation of MySQL, the default server encoding default is Latin1, then, do not panic, MySQL is very good, you can reset the encoding. Find the MySQLInstanceConfig.exe in the bin directory of MySQL, start this can program, the code of the server changed to Utf-8 on the line. Restart MySQL to perform the first step. Will find all the Latin1 have been changed to Utf-8 (of course, there is a filesystem is binary, no need to change).
Third: If you use Tomcat for communication, the default encoding for Tomcat is iso8859-1. This is the code you need to modify Tomcat: Modify the Conf/server.xml file under Tomcat
Find the following code:
<connectorport= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>
Add uriencoding= "UTF-8" on the line.
IV: When transferring Chinese
Stringdeviceintotime=deviceinfentity.getdeviceintotime ();
If there is Chinese, the Urlencoder.encode method should be
Params.addbodyparameter ("Deviceintotime", Urlencoder.encode (Deviceintotime, "utf-8"));
When receiving:
String deviceintotime =urldecoder.decode (Request.getparameter ("Deviceintotime"), "Utf-8");
Five: After the above steps, stored in the MySQL Chinese data or garbled, this is your database set up a problem.
For example I will appear:
Incorrect stringvalue: ' \\xE6\\xB7\\xB1\\xE5\\x85\\xA5 ... ' for column ' title ' at row 1 "
At this point, modify the properties of the database and select CharSet to Utf-8,collation as Utf8-unicode-ci. Remember that the table also involves the Chinese column also to choose CharSet for utf-8,collation for Utf8-unicode-ci. That's all.
When using Xutils, the POST request is passed in Chinese to the server side MySQL database is garbled.