Package org.apache.http.client.utils
Class URLEncodedUtils
- java.lang.Object
-
- org.apache.http.client.utils.URLEncodedUtils
-
@Immutable 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.StringCONTENT_TYPEThe default HTML form content type.
-
Constructor Summary
Constructors Constructor Description URLEncodedUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringformat(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-urlencodedlist of parameters in an HTTP PUT or HTTP POST.static java.lang.Stringformat(java.lang.Iterable<? extends NameValuePair> parameters, java.nio.charset.Charset charset)Returns a String that is suitable for use as anapplication/x-www-form-urlencodedlist of parameters in an HTTP PUT or HTTP POST.static java.lang.Stringformat(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-urlencodedlist of parameters in an HTTP PUT or HTTP POST.static java.lang.Stringformat(java.util.List<? extends NameValuePair> parameters, java.lang.String charset)Returns a String that is suitable for use as anapplication/x-www-form-urlencodedlist of parameters in an HTTP PUT or HTTP POST.static booleanisEncoded(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 ofNameValuePairsas parsed from the given string using the given character encoding.static java.util.List<NameValuePair>parse(java.lang.String s, java.nio.charset.Charset charset, char... parameterSeparator)Returns a list ofNameValuePairsas parsed from the given string using the given character encoding.static java.util.List<NameValuePair>parse(java.net.URI uri, java.lang.String charset)Returns a list ofNameValuePairsas built from the URI's query portion.static voidparse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String charset)Adds all parameters within the Scanner to the list ofparameters, as encoded byencoding.static voidparse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String parameterSepartorPattern, java.lang.String charset)Adds all parameters within the Scanner to the list ofparameters, as encoded byencoding.static java.util.List<NameValuePair>parse(HttpEntity entity)Returns a list ofNameValuePairsas parsed from anHttpEntity.
-
-
-
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
public static java.util.List<NameValuePair> parse(java.net.URI uri, java.lang.String charset)
Returns a list ofNameValuePairsas built from the URI's query portion. For example, a URI of http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for b=2, and one for c=3. By convention,'&'and';'are accepted as parameter separators.This is typically useful while parsing an HTTP PUT. This API is currently only used for testing.
- Parameters:
uri- URI to parsecharset- Charset name to use while parsing the query- Returns:
- a list of
NameValuePairas built from the URI's query portion.
-
parse
public static java.util.List<NameValuePair> parse(HttpEntity entity) throws java.io.IOException
Returns a list ofNameValuePairsas 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
NameValuePairas 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
public static void parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String 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=3would add theNameValuePairsa=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
public static void parse(java.util.List<NameValuePair> parameters, java.util.Scanner scanner, java.lang.String parameterSepartorPattern, java.lang.String 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=3would add theNameValuePairsa=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 ofNameValuePairsas parsed from the given string using the given character encoding. By convention,'&'and';'are accepted as parameter separators.- Parameters:
s- text to parse.charset- Encoding to use when decoding the parameters.- Returns:
- a list of
NameValuePairas built from the URI's query portion. - Since:
- 4.2
-
parse
public static java.util.List<NameValuePair> parse(java.lang.String s, java.nio.charset.Charset charset, char... parameterSeparator)
Returns a list ofNameValuePairsas parsed from the given string using the given character encoding.- Parameters:
s- text to parse.charset- Encoding to use when decoding the parameters.parameterSeparator- The characters used to separate parameters, by convention,'&'and';'.- Returns:
- a list of
NameValuePairas built from the URI's query portion. - Since:
- 4.3
-
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-urlencodedlist 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-urlencodedstring
-
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-urlencodedlist 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-urlencodedstring - 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-urlencodedlist 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-urlencodedstring - 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-urlencodedlist 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-urlencodedstring - Since:
- 4.3
-
-