org.apache.hc.client5.http.utils

## Class URLEncodedUtils

- java.lang.Object
- - org.apache.hc.client5.http.utils.URLEncodedUtils

    @Immutable
    public class URLEncodedUtils
    extends Object

A collection of utilities for encoding URLs.

Since:
  4.0

### Field Summary

Fields
`static String` `CONTENT_TYPE` The default HTML form content type.

### Constructor Summary

Constructors
Constructor and Description
`URLEncodedUtils()`

### Method Summary

Methods
`static String` `format(Iterable<? extends org.apache.hc.core5.http.NameValuePair> parameters, char parameterSeparator, Charset charset)` Returns a String that is suitable for use as an `application/x-www-form-urlencoded` list of parameters in an HTTP PUT or HTTP POST.
`static String` `format(Iterable<? extends org.apache.hc.core5.http.NameValuePair> parameters, Charset charset)` Returns a String that is suitable for use as an `application/x-www-form-urlencoded` list of parameters in an HTTP PUT or HTTP POST.
`static String` `format(List<? extends org.apache.hc.core5.http.NameValuePair> parameters, char parameterSeparator, String charset)` Returns a String that is suitable for use as an `application/x-www-form-urlencoded` list of parameters in an HTTP PUT or HTTP POST.
`static String` `format(List<? extends org.apache.hc.core5.http.NameValuePair> parameters, String charset)` Returns a String that is suitable for use as an `application/x-www-form-urlencoded` list of parameters in an HTTP PUT or HTTP POST.
`static boolean` `isEncoded(org.apache.hc.core5.http.HttpEntity entity)` Returns true if the entity's Content-Type header is `application/x-www-form-urlencoded`.
`static List<org.apache.hc.core5.http.NameValuePair>` `parse(org.apache.hc.core5.util.CharArrayBuffer buf, Charset charset, char... separators)` Returns a list of `NameValuePairs` as parsed from the given string using the given character encoding.
`static List<org.apache.hc.core5.http.NameValuePair>` `parse(org.apache.hc.core5.http.HttpEntity entity)` Returns a list of `NameValuePairs` as parsed from an `HttpEntity`.
`static List<org.apache.hc.core5.http.NameValuePair>` `parse(String s, Charset charset)` Returns a list of `NameValuePairs` as parsed from the given string using the given character encoding.
`static List<org.apache.hc.core5.http.NameValuePair>` `parse(String s, Charset charset, char... separators)` Returns a list of `NameValuePairs` as parsed from the given string using the given character encoding.
`static List<org.apache.hc.core5.http.NameValuePair>` `parse(URI uri, String charset)` Returns a list of `NameValuePairs` as built from the URI's query portion.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### CONTENT_TYPE

    public static final String CONTENT_TYPE

The default HTML form content type.

See Also:
  Constant Field Values

### Constructor Detail

#### URLEncodedUtils

    public URLEncodedUtils()

### Method Detail

#### parse

    public static List<org.apache.hc.core5.http.NameValuePair> parse(URI uri,
                                                     String charset)

Returns a list of `NameValuePairs` as 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 parse
  `charset` - Charset name to use while parsing the query
Returns:
  a list of `NameValuePair` as built from the URI's query portion.

#### parse

    public static List<org.apache.hc.core5.http.NameValuePair> parse(org.apache.hc.core5.http.HttpEntity entity)
                                                              throws IOException

Returns a list of `NameValuePairs` as parsed from an `HttpEntity`. 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:
  `IOException` - If there was an exception getting the entity's data.

#### isEncoded

    public static boolean isEncoded(org.apache.hc.core5.http.HttpEntity entity)

Returns true if the entity's Content-Type header is `application/x-www-form-urlencoded`.

#### parse

    public static List<org.apache.hc.core5.http.NameValuePair> parse(String s,
                                                     Charset charset)

Returns a list of `NameValuePairs` as 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 `NameValuePair` as built from the URI's query portion.
Since:
  4.2

#### parse

    public static List<org.apache.hc.core5.http.NameValuePair> parse(String s,
                                                     Charset charset,
                                                     char... separators)

Returns a list of `NameValuePairs` as parsed from the given string using the given character encoding.

Parameters:
  `s` - 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.3

#### parse

    public static List<org.apache.hc.core5.http.NameValuePair> parse(org.apache.hc.core5.util.CharArrayBuffer buf,
                                                     Charset charset,
                                                     char... separators)

Returns a list of `NameValuePairs` as parsed from the given string using the given character encoding.

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

#### format

    public static String format(List<? extends org.apache.hc.core5.http.NameValuePair> parameters,
                String charset)

Returns a String that is suitable for use as an `application/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 String format(List<? extends org.apache.hc.core5.http.NameValuePair> parameters,
                char parameterSeparator,
                String charset)

Returns a String that is suitable for use as an `application/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 String format(Iterable<? extends org.apache.hc.core5.http.NameValuePair> parameters,
                Charset charset)

Returns a String that is suitable for use as an `application/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 String format(Iterable<? extends org.apache.hc.core5.http.NameValuePair> parameters,
                char parameterSeparator,
                Charset charset)

Returns a String that is suitable for use as an `application/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