Garbled------encoded conversions in HTTP requests

Source: Internet
Author: User

In the HTTP request if contains the Chinese character, then will appear garbled, the citation default encoding is the ISO, for the normal display, needs to convert the code to UTF or GBK, provides an auxiliary class below.

Import java.io.UnsupportedEncodingException;

/**
* Auxiliary class for Chinese character transcoding
* @date 2015-09-06 10:29:22
* @author GEENKDC
*
*/
public class iso2utf{

public static string Iso2utf (String isostr) {
String utfstr = null;
try {
Transcoding of Chinese characters in the import parameter
Utfstr = new String (isostr.getbytes ("iso-8859-1"), "UTF-8");

} catch (Unsupportedencodingexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return utfstr;
}
public static string ISO2GBK (String isostr) {
String utfstr = null;
try {
Transcoding of Chinese characters in the import parameter
Utfstr = new String (isostr.getbytes ("iso-8859-1"), "GBK");

} catch (Unsupportedencodingexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
return utfstr;
}
}

Garbled------encoded conversions in HTTP requests

Related Article

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.