urlencode and urldecode in java
import java.net.URLDecoder;
import java.net.URLEncoder;
import junit.framework.TestCase;
public class URLEncodeAndDecode extends TestCase {
public void testUrlEncode() throws Exception {
String str = "中文";
String utf8Code = URLEncoder.encode(str, "UTF-8");
assertEquals("%E4%B8%AD%E6%96%87", utf8Code);
String gbkCode = URLEncoder.encode(str, "GBK");
assertEquals("%D6%D0%CE%C4", gbkCode);
assertEquals("中文", URLDecoder.decode("%E4%B8%AD%E6%96%87", "UTF-8"));
assertEquals("中文", URLDecoder.decode("%D6%D0%CE%C4", "GBK"));
}
}
import java.net.URLEncoder;
import junit.framework.TestCase;
public class URLEncodeAndDecode extends TestCase {
public void testUrlEncode() throws Exception {
String str = "中文";
String utf8Code = URLEncoder.encode(str, "UTF-8");
assertEquals("%E4%B8%AD%E6%96%87", utf8Code);
String gbkCode = URLEncoder.encode(str, "GBK");
assertEquals("%D6%D0%CE%C4", gbkCode);
assertEquals("中文", URLDecoder.decode("%E4%B8%AD%E6%96%87", "UTF-8"));
assertEquals("中文", URLDecoder.decode("%D6%D0%CE%C4", "GBK"));
}
}
No comments :
Post a Comment