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 data) |
Modifier and Type | Method and Description |
---|---|
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 ). |
Object |
getData()
Returns the key name/value data or
null for none. |
UrlEncodedContent |
setData(Object data)
Sets the key name/value data.
|
UrlEncodedContent |
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or
null if unspecified. |
void |
writeTo(OutputStream out)
Writes the content to the given output stream.
|
computeLength, getCharset, getEncoding, getLength, getMediaType, getType, retrySupported
public UrlEncodedContent(Object data)
data
- key name/value datapublic void writeTo(OutputStream out) throws IOException
HttpContent
The recommendation for implementations is that they should not close the output stream. Callers should not assume whether or not the output stream has been closed. Implementations that do not close the output stream should flush it at the end of the method.
IOException
public UrlEncodedContent setMediaType(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.
setMediaType
in class AbstractHttpContent
public final Object getData()
null
for none.public UrlEncodedContent setData(Object data)
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public static UrlEncodedContent getContent(HttpRequest request)
UrlEncodedContent
(whose getData()
is an implementation of
Map
).request
- HTTP requestClassCastException
- if the HTTP request has a content defined that is not
UrlEncodedContent
Copyright © 2011-2012 Google. All Rights Reserved.