Class UrlEncodedContent (1.45.1)

public class UrlEncodedContent extends AbstractHttpContent

Implements support for HTTP form content encoding serialization of type application/x-www-form-urlencoded as specified in the HTML 4.0 Specification.

Sample usage:

static void setContent(HttpRequest request, Object item) { request.setContent(new UrlEncodedContent(item)); }

Implementation is not thread-safe.

Inheritance

Object > AbstractHttpContent > UrlEncodedContent

Static Methods

getContent(HttpRequest request)

public static UrlEncodedContent getContent(HttpRequest request)

Returns the URL-encoded content of the given HTTP request, or if none return and set as content a new instance of UrlEncodedContent (whose #getData() is an implementation of Map).

Parameter
Name Description
request HttpRequest

HTTP request

Returns
Type Description
UrlEncodedContent

URL-encoded content

Constructors

UrlEncodedContent(Object data)

public UrlEncodedContent(Object data)

Initialize the UrlEncodedContent with the legacy and deprecated escapeUri encoder

Parameter
Name Description
data Object

key name/value data

UrlEncodedContent(Object data, boolean useUriPathEncoding)

public UrlEncodedContent(Object data, boolean useUriPathEncoding)

Initialize the UrlEncodedContent with or without the legacy and deprecated escapeUri encoder

Parameters
Name Description
data Object

key name/value data

useUriPathEncoding boolean

escapes the string value so it can be safely included in URI path segments. For details on escaping URIs, see RFC 3986 - section 2.4

Methods

getData()

public final Object getData()

Returns the key name/value data or null for none.

Returns
Type Description
Object

setData(Object data)

public UrlEncodedContent setData(Object data)

Sets the key name/value data.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
Name Description
data Object
Returns
Type Description
UrlEncodedContent

setMediaType(HttpMediaType mediaType)

public UrlEncodedContent setMediaType(HttpMediaType mediaType)

Sets the media type to use for the Content-Type header, or null if unspecified.

This will also overwrite any previously set parameter of the media type (for example "charset"), and therefore might change other properties as well.

Parameter
Name Description
mediaType HttpMediaType
Returns
Type Description
UrlEncodedContent
Overrides

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
Name Description
out OutputStream
Exceptions
Type Description
IOException