Class UrlEncodedContent (1.41.8)

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
NameDescription
requestHttpRequest

HTTP request

Returns
TypeDescription
UrlEncodedContent

URL-encoded content

Constructors

UrlEncodedContent(Object data)

public UrlEncodedContent(Object data)

Initialize the UrlEncodedContent with the legacy and deprecated escapeUri encoder

Parameter
NameDescription
dataObject

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
NameDescription
dataObject

key name/value data

useUriPathEncodingboolean

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
TypeDescription
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
NameDescription
dataObject
Returns
TypeDescription
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
NameDescription
mediaTypeHttpMediaType
Returns
TypeDescription
UrlEncodedContent
Overrides

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
NameDescription
outOutputStream
Exceptions
TypeDescription
IOException