public class UrlEncodedContent extends AbstractHttpContent
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.
| Constructor and Description |
|---|
UrlEncodedContent(Object
|
| Modifier and Type | Method and Description |
|---|---|
static UrlEncodedContent |
getContent(HttpRequest
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).
|
Object |
getData()
Returns the key name/value data or
null for none.
|
UrlEncodedContent |
setData(Object
Sets the key name/value data.
|
UrlEncodedContent |
setMediaType(HttpMediaType
Sets the media type to use for the Content-Type header, or
null if unspecified.
|
void |
writeTo(OutputStream
Writes the byte content to the given output stream.
|
computeLength, computeLength, getCharset, getLength, getMediaType, getType, retrySupportedpublic UrlEncodedContent(Objectdata)
data - key name/value data
public void writeTo(OutputStreamout) throws IOException
StreamingContent
Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the the output stream has not been closed, and will fail to work if it has been closed.
out - output stream
IOException
public UrlEncodedContentsetMediaType(HttpMediaType mediaType)
AbstractHttpContent
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.
public final ObjectgetData()
null for none.
public UrlEncodedContentsetData(Object data)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public static UrlEncodedContentgetContent(HttpRequest request)
UrlEncodedContent (whose
getData() is an implementation of
Map).
request - HTTP request
ClassCastException - if the HTTP request has a content defined that is not
UrlEncodedContent