解码百度移动端 URL 的编码方式

import java.net.URLDecoder;

/**
 * 解析移动URL 中  中文字符问题
 * http://m5.baidu.com/from=1089a/s?word=%259d%2571%2566%259e%2554%2576%25a0%2560%2574%259e%2543%2561&st=11104i&ts=4691535&sa=ih_2&ss=01&ix=404%25
 * @author GT
 *
 */
public class UrlTest {

	public static void main(String[] args) throws Exception {
		String url_0 = "%259d%2571%2566%259e%2554%2576%25a0%2560%2574%259e%2543%2561";
		//1 去掉 25
		String url_1 = "%9d%71%66%9e%54%76%a0%60%74%9e%43%61";
		
		String[] url_2 = url_1.split("%");
		
		StringBuilder url_3 = new StringBuilder();
		for(int i=1;i<url_2.length;i++){
			String str = url_2[i];
			String res = Integer.valueOf(str,16).toString();
			int intRes = Integer.parseInt(res);
			intRes = intRes+256;
			intRes = intRes-201;
			String str_16 = Integer.toHexString(intRes+16);
			url_3.append("%"+str_16);
		}
		System.out.println(url_3.toString());
		String strRes = URLDecoder.decode(url_3.toString(),"UTF-8");
		System.out.println(strRes);
	}
	
}


参考贴:http://www.zhihu.com/topic/19599871/newest


你可能感兴趣的:(解码百度移动端 URL 的编码方式)