URL编码机制
Java与URL编码
编码
URLEncoder.encode( URL, "UTF-8" );
解码
URLDecoder.decode( URL, "UTF-8" );
实验
1 String strEncode= URLEncoder.encode("https://www.baidu.com/s?wd=编码","UTF-8"); 2 String strDecode= URLDecoder.decode("https://www.baidu.com/s?wd=%E7%BC%96%E7%A0%81", "UTF-8" ); 3 System.out.println(strEncode); 4 System.out.println(strDecode);
输出
1 https%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3D%E7%BC%96%E7%A0%81 2 https://www.baidu.com/s?wd=编码