public class UrlCoder extends Object
Util methods for encode / decode uri.
Encode diffs between url path segment, path parameter, and query part, follow the RFC3986:For HTTP URLs, a space in a path fragment part has to be encoded to "%20" (not, absolutely not "+"), while the "+" character in the path fragment part can be left unencoded. Now in the query part, spaces may be encoded to either "+" (just for backwards compatibility) or "%20" while the "+" character has to be escaped to "%2B".
"?" is allowed unescaped anywhere within a query part,
"/" is allowed unescaped anywhere within a query part,
"=" is allowed unescaped anywhere within a path parameter or query parameter value, and within a path segment,
":@-._~!$&'()*+,;=" are allowed unescaped anywhere within a path segment part,
"/?:@-._~!$&'()*+,;=" are allowed unescaped anywhere within a fragment part.
For "https://bob:bobby@www.lunatech.com:8080/file;p=1?q=2#third", we can extract the following information:
Scheme https
User bob
Password bobby
Host address www.lunatech.com
Port 8080
Path /file
Path parameters p=1
Query parameters q=2
Fragment third
java.net.URLEncoder is used to convert a String to the application/x-www-form-urlencoded MIME format,
which is not suitable for encode urls| 构造器和说明 |
|---|
UrlCoder() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
_decode(String s,
Charset charset,
boolean isQueryPart) |
static String |
decodeFragment(String s,
Charset charset)
decode url fragment
|
static String |
decodeFragment(String s,
String charset)
decode url fragment
|
static String |
decodePathSegment(String s,
Charset charset)
decode url path segment
|
static String |
decodePathSegment(String s,
String charset)
decode url path segment
|
static String |
decodeQuery(String s,
Charset charset)
decode query parameter: key and value
|
static String |
decodeQuery(String s,
String charset)
decode query parameter: key and value
|
static String |
encodeFragment(String s,
Charset charset)
encode url fragment
|
static String |
encodeFragment(String s,
String charset)
encode url fragment
|
static String |
encodePathSegment(String s,
Charset charset)
encode url path segment
|
static String |
encodePathSegment(String s,
String charset)
encode url path segment
|
static String |
encodeQuery(String s,
Charset charset)
used to encode query parameter: key and value
|
static String |
encodeQuery(String s,
String charset)
used to encode query parameter: key and value
|
public static String encodeQuery(String s, String charset)
public static String encodeQuery(String s, Charset charset)
public static String decodeQuery(String s, String charset)
public static String decodeQuery(String s, Charset charset)
public static String encodePathSegment(String s, String charset)
public static String encodePathSegment(String s, Charset charset)
public static String decodePathSegment(String s, String charset)
public static String decodePathSegment(String s, Charset charset)
Copyright © 2015. All rights reserved.