/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string using the given character * encoding. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. * * @param s * text to parse. * @param charset * Encoding to use when decoding the parameters. * @return a list of {@link NameValuePair} as built from the URI's query portion. * * @since 4.2 */ public static List<NameValuePair> parse(final String s, final Charset charset) { return parse(s, charset, QP_SEPS); }
/** * Adds all parameters within the Scanner to the list of <code>parameters</code>, as encoded by * <code>encoding</code>. For example, a scanner containing the string <code>a=1&b=2&c=3</code> would add the * {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the list of parameters. By convention, {@code '&'} and * {@code ';'} are accepted as parameter separators. * * @param parameters * List to add parameters to. * @param scanner * Input that contains the parameters to parse. * @param charset * Encoding to use when decoding the parameters. */ public static void parse( final List <NameValuePair> parameters, final Scanner scanner, final String charset) { parse(parameters, scanner, QP_SEP_PATTERN, charset); }
private List <NameValuePair> parseQuery(final String query, final Charset charset) { if (query != null && query.length() > 0) { return URLEncodedUtilsHC4.parse(query, charset); } return null; }
/** * 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. By convention, {@code '&'} and {@code ';'} are accepted as parameter separators. * <p> * This is typically useful while parsing an HTTP PUT. * * This API is currently only used for testing. * * @param uri * URI to parse * @param charset * Charset name to use while parsing the query * @return a list of {@link NameValuePair} as built from the URI's query portion. */ public static List <NameValuePair> parse(final URI uri, final String charset) { final String query = uri.getRawQuery(); if (query != null && query.length() > 0) { final List<NameValuePair> result = new ArrayList<NameValuePair>(); final Scanner scanner = new Scanner(query); parse(result, scanner, QP_SEP_PATTERN, charset); return result; } return Collections.emptyList(); }
/** * Returns a list of {@link NameValuePair NameValuePairs} as parsed from an {@link HttpEntity}. The encoding is * taken from the entity's Content-Encoding header. * <p> * This is typically used while parsing an HTTP POST. * * @param entity * The entity to parse * @return a list of {@link NameValuePair} as built from the URI's query portion. * @throws IOException * If there was an exception getting the entity's data. */ public static List <NameValuePair> parse( final HttpEntity entity) throws IOException { final ContentType contentType = ContentType.get(entity); if (contentType != null && contentType.getMimeType().equalsIgnoreCase(CONTENT_TYPE)) { final String content = EntityUtilsHC4.toString(entity, Consts.ASCII); if (content != null && content.length() > 0) { Charset charset = contentType.getCharset(); if (charset == null) { charset = Charset.forName(HTTP.DEFAULT_CONTENT_CHARSET); } return parse(content, charset, QP_SEPS); } } return Collections.emptyList(); }