Methods Summary |
---|
private static java.lang.String | decode(java.lang.String content, java.lang.String encoding)
try {
return URLDecoder.decode(content,
encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException problem) {
throw new IllegalArgumentException(problem);
}
|
private static java.lang.String | encode(java.lang.String content, java.lang.String encoding)
try {
return URLEncoder.encode(content,
encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException problem) {
throw new IllegalArgumentException(problem);
}
|
public static java.lang.String | format(java.util.List parameters, java.lang.String encoding)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.
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
final String encodedName = encode(parameter.getName(), encoding);
final String value = parameter.getValue();
final String encodedValue = value != null ? encode(value, encoding) : "";
if (result.length() > 0)
result.append(PARAMETER_SEPARATOR);
result.append(encodedName);
result.append(NAME_VALUE_SEPARATOR);
result.append(encodedValue);
}
return result.toString();
|
public static boolean | isEncoded(org.apache.http.HttpEntity entity)Returns true if the entity's Content-Type header is
application/x-www-form-urlencoded .
final Header contentType = entity.getContentType();
return (contentType != null && contentType.getValue().equalsIgnoreCase(CONTENT_TYPE));
|
public static java.util.List | parse(java.net.URI uri, java.lang.String encoding)Returns a list of {@link NameValuePair 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.
This is typically useful while parsing an HTTP PUT.
List <NameValuePair> result = Collections.emptyList();
final String query = uri.getRawQuery();
if (query != null && query.length() > 0) {
result = new ArrayList <NameValuePair>();
parse(result, new Scanner(query), encoding);
}
return result;
|
public static java.util.List | parse(org.apache.http.HttpEntity entity)Returns a list of {@link NameValuePair NameValuePairs} as parsed from an
{@link HttpEntity}. The encoding is taken from the entity's
Content-Encoding header.
This is typically used while parsing an HTTP POST.
List <NameValuePair> result = Collections.emptyList();
if (isEncoded(entity)) {
final String content = EntityUtils.toString(entity);
final Header encoding = entity.getContentEncoding();
if (content != null && content.length() > 0) {
result = new ArrayList <NameValuePair>();
parse(result, new Scanner(content),
encoding != null ? encoding.getValue() : null);
}
}
return result;
|
public static void | parse(java.util.List parameters, java.util.Scanner scanner, java.lang.String encoding)Adds all parameters within the Scanner to the list of
parameters , as encoded by encoding . For
example, a scanner containing the string a=1&b=2&c=3 would
add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the
list of parameters.
scanner.useDelimiter(PARAMETER_SEPARATOR);
while (scanner.hasNext()) {
final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR);
if (nameValue.length == 0 || nameValue.length > 2)
throw new IllegalArgumentException("bad parameter");
final String name = decode(nameValue[0], encoding);
String value = null;
if (nameValue.length == 2)
value = decode(nameValue[1], encoding);
parameters.add(new BasicNameValuePair(name, value));
}
|