Search in sources :

Example 56 with NameValuePair

use of org.apache.http.NameValuePair in project XobotOS by xamarin.

the class BasicHeaderValueParser method parseHeaderElement.

// non-javadoc, see interface HeaderValueParser
public HeaderElement parseHeaderElement(final CharArrayBuffer buffer, final ParserCursor cursor) {
    if (buffer == null) {
        throw new IllegalArgumentException("Char array buffer may not be null");
    }
    if (cursor == null) {
        throw new IllegalArgumentException("Parser cursor may not be null");
    }
    NameValuePair nvp = parseNameValuePair(buffer, cursor);
    NameValuePair[] params = null;
    if (!cursor.atEnd()) {
        char ch = buffer.charAt(cursor.getPos() - 1);
        if (ch != ELEM_DELIMITER) {
            params = parseParameters(buffer, cursor);
        }
    }
    return createHeaderElement(nvp.getName(), nvp.getValue(), params);
}
Also used : NameValuePair(org.apache.http.NameValuePair)

Example 57 with NameValuePair

use of org.apache.http.NameValuePair in project xUtils by wyouflf.

the class OtherUtils method getCharsetFromHttpRequest.

public static Charset getCharsetFromHttpRequest(final HttpRequestBase request) {
    if (request == null)
        return null;
    String charsetName = null;
    Header header = request.getFirstHeader("Content-Type");
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair charsetPair = element.getParameterByName("charset");
            if (charsetPair != null) {
                charsetName = charsetPair.getValue();
                break;
            }
        }
    }
    boolean isSupportedCharset = false;
    if (!TextUtils.isEmpty(charsetName)) {
        try {
            isSupportedCharset = Charset.isSupported(charsetName);
        } catch (Throwable e) {
        }
    }
    return isSupportedCharset ? Charset.forName(charsetName) : null;
}
Also used : NameValuePair(org.apache.http.NameValuePair) Header(org.apache.http.Header) HeaderElement(org.apache.http.HeaderElement)

Example 58 with NameValuePair

use of org.apache.http.NameValuePair in project xUtils by wyouflf.

the class URLEncodedUtils method format.

/**
     * Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
     * list of parameters in an HTTP PUT or HTTP POST.
     *
     * @param parameters The parameters to include.
     * @param charset    The encoding to use.
     * @since 4.2
     */
public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) {
    final StringBuilder result = new StringBuilder();
    for (final NameValuePair parameter : parameters) {
        final String encodedName = encodeFormFields(parameter.getName(), charset);
        final String encodedValue = encodeFormFields(parameter.getValue(), charset);
        if (result.length() > 0) {
            result.append(PARAMETER_SEPARATOR);
        }
        result.append(encodedName);
        if (encodedValue != null) {
            result.append(NAME_VALUE_SEPARATOR);
            result.append(encodedValue);
        }
    }
    return result.toString();
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair)

Example 59 with NameValuePair

use of org.apache.http.NameValuePair in project xUtils by wyouflf.

the class URIBuilder method addParameter.

/**
     * Adds parameter to URI query. The parameter name and value are expected to be unescaped
     * and may contain non ASCII characters.
     */
public URIBuilder addParameter(final String param, final String value) {
    if (this.queryParams == null) {
        this.queryParams = new ArrayList<NameValuePair>();
    }
    this.queryParams.add(new BasicNameValuePair(param, value));
    this.encodedQuery = null;
    this.encodedSchemeSpecificPart = null;
    return this;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 60 with NameValuePair

use of org.apache.http.NameValuePair in project xUtils by wyouflf.

the class URIBuilder method setParameter.

/**
     * Sets parameter of URI query overriding existing value if set. The parameter name and value
     * are expected to be unescaped and may contain non ASCII characters.
     */
public URIBuilder setParameter(final String param, final String value) {
    if (this.queryParams == null) {
        this.queryParams = new ArrayList<NameValuePair>();
    }
    if (!this.queryParams.isEmpty()) {
        for (final Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
            final NameValuePair nvp = it.next();
            if (nvp.getName().equals(param)) {
                it.remove();
            }
        }
    }
    this.queryParams.add(new BasicNameValuePair(param, value));
    this.encodedQuery = null;
    this.encodedSchemeSpecificPart = null;
    return this;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Aggregations

NameValuePair (org.apache.http.NameValuePair)713 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)592 ArrayList (java.util.ArrayList)478 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)256 HttpPost (org.apache.http.client.methods.HttpPost)218 HttpResponse (org.apache.http.HttpResponse)150 IOException (java.io.IOException)125 HttpEntity (org.apache.http.HttpEntity)108 Test (org.junit.Test)85 URI (java.net.URI)79 Map (java.util.Map)72 HashMap (java.util.HashMap)68 HttpGet (org.apache.http.client.methods.HttpGet)66 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)55 URISyntaxException (java.net.URISyntaxException)52 Document (org.jsoup.nodes.Document)51 URIBuilder (org.apache.http.client.utils.URIBuilder)50 HttpClient (org.apache.http.client.HttpClient)46