public class URLEncoder extends Object implements Serializable
1.字符"a"-"z","A"-"Z","0"-"9",".","-","*",和"_" 都不会被编码; 2.将空格转换为%20 ; 3.将非文本内容转换成"%xy"的形式,xy是两位16进制的数值;
Modifier and Type | Field and Description |
---|---|
static URLEncoder |
ALL
全编码的URLEncoder
|
static URLEncoder |
DEFAULT
默认URLEncoder
默认的编码器针对URI路径编码,定义如下: |
static URLEncoder |
QUERY
用于查询语句的URLEncoder
编码器针对URI路径编码,定义如下: |
Constructor and Description |
---|
URLEncoder()
构造
|
Modifier and Type | Method and Description |
---|---|
void |
addSafeCharacter(char c)
增加安全字符
安全字符不被编码 |
static URLEncoder |
createAll()
创建URLEncoder
编码器针对URI路径编码,定义如下: |
static URLEncoder |
createDefault()
创建默认URLEncoder
默认的编码器针对URI路径编码,定义如下: |
static URLEncoder |
createQuery()
创建用于查询语句的URLEncoder
编码器针对URI路径编码,定义如下: |
String |
encode(String path,
Charset charset)
将URL中的字符串编码为%形式
|
void |
removeSafeCharacter(char c)
移除安全字符
安全字符不被编码 |
void |
setEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)
是否将空格编码为+
|
public static final URLEncoder DEFAULT
pchar = unreserved(不处理) / pct-encoded / sub-delims(子分隔符) / ":" / "@" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
public static final URLEncoder QUERY
0x20 ' ' =》 '+' 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' Also '=' and '&' 不编码 其它编码为 %nn 形式
详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
public static final URLEncoder ALL
0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' 不编码 其它编码为 %nn 形式
public static URLEncoder createDefault()
pchar = unreserved(不处理) / pct-encoded / sub-delims(子分隔符) / ":" / "@" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
public static URLEncoder createQuery()
0x20 ' ' =》 '+' 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' Also '=' and '&' 不编码 其它编码为 %nn 形式
详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
public static URLEncoder createAll()
0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A as-is '*', '-', '.', '0' to '9', 'A' to 'Z', '_', 'a' to 'z' 不编码 其它编码为 %nn 形式
详细见:https://www.w3.org/TR/html5/forms.html#application/x-www-form-urlencoded-encoding-algorithm
public void addSafeCharacter(char c)
c
- 字符public void removeSafeCharacter(char c)
c
- 字符public void setEncodeSpaceAsPlus(boolean encodeSpaceAsPlus)
encodeSpaceAsPlus
- 是否将空格编码为+Copyright © 2021. All rights reserved.