URL编解码

package t1;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

//URL编码
public class SecUrl {

public static void main(String[] args) throws UnsupportedEncodingException {
String original = "URL 参数";
String encoded = URLEncoder.encode(original, "UTF-8");
System.out.println(encoded);
System.out.println(URLDecoder.decode(encoded, "UTF-8"));
}

}

 

输出:

URL+%E5%8F%82%E6%95%B0
URL 参数

 

URL编码不是加密算法,他把英文数字 减号中划线星号点号原样输出,

把中文等其他字符用%的前缀输出,空格以加号或者%20输出。

 

posted @ 2020-05-10 01:17  工设091  阅读(138)  评论(0)    收藏  举报