Package org.apache.http.client.utils
Class URLEncodedUtils
- java.lang.Object
-
- org.apache.http.client.utils.URLEncodedUtils
-
public class URLEncodedUtils extends java.lang.Object
A collection of utilities for encoding URLs.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTENT_TYPE
The default HTML form content type.
-
Constructor Summary
Constructors Constructor Description URLEncodedUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
format(java.lang.Iterable<? extends NameValuePair> parameters, char parameterSeparator, java.nio.charset.Charset charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.static java.lang.String
format(java.lang.Iterable<? extends NameValuePair> parameters, java.nio.charset.Charset charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.static java.lang.String
format(java.util.List<? extends NameValuePair> parameters, char parameterSeparator, java.lang.String charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.static java.lang.String
format(java.util.List<? extends NameValuePair> parameters, java.lang.String charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.static java.lang.String
formatSegments(java.lang.Iterable<java.lang.String> segments, java.nio.charset.Charset charset)
Returns a string consisting of joint encoded path segments.static java.lang.String
formatSegments(java.lang.String... segments)
Returns a string consisting of joint encoded path segments.static boolean
isEncoded(HttpEntity entity)
Returns true if the entity's Content-Type header isapplication/x-www-form-urlencoded
.static java.util.List<NameValuePair>
parse(java.lang.String s, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s URI query parameters.static java.util.List<NameValuePair>
parse(java.lang.String s, java.nio.charset.Charset charset, char... separators)
Returns a list ofNameValuePairs
as parsed from the given string using the given character encoding.static java.util.List<NameValuePair>
parse(java.net.URI uri, java.lang.String charsetName)
Deprecated.4.5 Useparse(URI, Charset)
static java.util.List<NameValuePair>
parse(java.net.URI uri, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s URI query parameters.static void
parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String charset)
Deprecated.(4.4) useparse(String, java.nio.charset.Charset)
static void
parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String parameterSepartorPattern, java.lang.String charset)
Deprecated.static java.util.List<NameValuePair>
parse(HttpEntity entity)
Returns a list ofNameValuePairs
as parsed from anHttpEntity
.static java.util.List<NameValuePair>
parse(CharArrayBuffer buf, java.nio.charset.Charset charset, char... separators)
Returns a list ofNameValuePair
s parameters.static java.util.List<java.lang.String>
parsePathSegments(java.lang.CharSequence s)
Returns a list of URI path segments.static java.util.List<java.lang.String>
parsePathSegments(java.lang.CharSequence s, java.nio.charset.Charset charset)
Returns a list of URI path segments.
-
-
-
Field Detail
-
CONTENT_TYPE
public static final java.lang.String CONTENT_TYPE
The default HTML form content type.- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
@Deprecated public static java.util.List<NameValuePair> parse(java.net.URI uri, java.lang.String charsetName)
Deprecated.4.5 Useparse(URI, Charset)
-
parse
public static java.util.List<NameValuePair> parse(java.net.URI uri, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s URI query parameters. By convention,'&'
and';'
are accepted as parameter separators.- Parameters:
uri
- input URI.charset
- parameter charset.- Returns:
- list of query parameters.
- Since:
- 4.5
-
parse
public static java.util.List<NameValuePair> parse(HttpEntity entity) throws java.io.IOException
Returns a list ofNameValuePairs
as parsed from anHttpEntity
. The encoding is taken from the entity's Content-Encoding header.This is typically used while parsing an HTTP POST.
- Parameters:
entity
- The entity to parse- Returns:
- a list of
NameValuePair
as built from the URI's query portion. - Throws:
java.io.IOException
- If there was an exception getting the entity's data.
-
isEncoded
public static boolean isEncoded(HttpEntity entity)
Returns true if the entity's Content-Type header isapplication/x-www-form-urlencoded
.
-
parse
@Deprecated public static void parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String charset)
Deprecated.(4.4) useparse(String, java.nio.charset.Charset)
Adds all parameters within the Scanner to the list ofparameters
, as encoded byencoding
. For example, a scanner containing the stringa=1&b=2&c=3
would add theNameValuePairs
a=1, b=2, and c=3 to the list of parameters. By convention,'&'
and';'
are accepted as parameter separators.- Parameters:
parameters
- List to add parameters to.scanner
- Input that contains the parameters to parse.charset
- Encoding to use when decoding the parameters.
-
parse
@Deprecated public static void parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String parameterSepartorPattern, java.lang.String charset)
Deprecated.Adds all parameters within the Scanner to the list ofparameters
, as encoded byencoding
. For example, a scanner containing the stringa=1&b=2&c=3
would add theNameValuePairs
a=1, b=2, and c=3 to the list of parameters.- Parameters:
parameters
- List to add parameters to.scanner
- Input that contains the parameters to parse.parameterSepartorPattern
- The Pattern string for parameter separators, by convention"[&;]"
charset
- Encoding to use when decoding the parameters.
-
parse
public static java.util.List<NameValuePair> parse(java.lang.String s, java.nio.charset.Charset charset)
Returns a list ofNameValuePair
s URI query parameters. By convention,'&'
and';'
are accepted as parameter separators.- Parameters:
s
- URI query component.charset
- charset to use when decoding the parameters.- Returns:
- list of query parameters.
- Since:
- 4.2
-
parse
public static java.util.List<NameValuePair> parse(java.lang.String s, java.nio.charset.Charset charset, char... separators)
Returns a list ofNameValuePairs
as parsed from the given string using the given character encoding.- Parameters:
s
- input text.charset
- parameter charset.separators
- parameter separators.- Returns:
- list of query parameters.
- Since:
- 4.3
-
parse
public static java.util.List<NameValuePair> parse(CharArrayBuffer buf, java.nio.charset.Charset charset, char... separators)
Returns a list ofNameValuePair
s parameters.- Parameters:
buf
- text to parse.charset
- Encoding to use when decoding the parameters.separators
- element separators.- Returns:
- a list of
NameValuePair
as built from the URI's query portion. - Since:
- 4.4
-
parsePathSegments
public static java.util.List<java.lang.String> parsePathSegments(java.lang.CharSequence s, java.nio.charset.Charset charset)
Returns a list of URI path segments.- Parameters:
s
- URI path component.charset
- parameter charset.- Returns:
- list of segments.
- Since:
- 4.5
-
parsePathSegments
public static java.util.List<java.lang.String> parsePathSegments(java.lang.CharSequence s)
Returns a list of URI path segments.- Parameters:
s
- URI path component.- Returns:
- list of segments.
- Since:
- 4.5
-
formatSegments
public static java.lang.String formatSegments(java.lang.Iterable<java.lang.String> segments, java.nio.charset.Charset charset)
Returns a string consisting of joint encoded path segments.- Parameters:
segments
- the segments.charset
- parameter charset.- Returns:
- URI path component
- Since:
- 4.5
-
formatSegments
public static java.lang.String formatSegments(java.lang.String... segments)
Returns a string consisting of joint encoded path segments.- Parameters:
segments
- the segments.- Returns:
- URI path component
- Since:
- 4.5
-
format
public static java.lang.String format(java.util.List<? extends NameValuePair> parameters, java.lang.String charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.- Parameters:
parameters
- The parameters to include.charset
- The encoding to use.- Returns:
- An
application/x-www-form-urlencoded
string
-
format
public static java.lang.String format(java.util.List<? extends NameValuePair> parameters, char parameterSeparator, java.lang.String charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.- Parameters:
parameters
- The parameters to include.parameterSeparator
- The parameter separator, by convention,'&'
or';'
.charset
- The encoding to use.- Returns:
- An
application/x-www-form-urlencoded
string - Since:
- 4.3
-
format
public static java.lang.String format(java.lang.Iterable<? extends NameValuePair> parameters, java.nio.charset.Charset charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.- Parameters:
parameters
- The parameters to include.charset
- The encoding to use.- Returns:
- An
application/x-www-form-urlencoded
string - Since:
- 4.2
-
format
public static java.lang.String format(java.lang.Iterable<? extends NameValuePair> parameters, char parameterSeparator, java.nio.charset.Charset charset)
Returns a String that is suitable for use as anapplication/x-www-form-urlencoded
list of parameters in an HTTP PUT or HTTP POST.- Parameters:
parameters
- The parameters to include.parameterSeparator
- The parameter separator, by convention,'&'
or';'
.charset
- The encoding to use.- Returns:
- An
application/x-www-form-urlencoded
string - Since:
- 4.3
-
-