Search in sources :

Example 46 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class URIBuilder method formatQuery.

static void formatQuery(final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset, final boolean blankAsPlus) {
    int i = 0;
    for (final NameValuePair parameter : params) {
        if (i > 0) {
            buf.append(QUERY_PARAM_SEPARATOR);
        }
        PercentCodec.encode(buf, parameter.getName(), charset, blankAsPlus);
        if (parameter.getValue() != null) {
            buf.append(PARAM_VALUE_SEPARATOR);
            PercentCodec.encode(buf, parameter.getValue(), charset, blankAsPlus);
        }
        i++;
    }
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair)

Example 47 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class URIBuilder method parseQuery.

static List<NameValuePair> parseQuery(final CharSequence s, final Charset charset, final boolean plusAsBlank) {
    if (s == null) {
        return null;
    }
    final Tokenizer tokenParser = Tokenizer.INSTANCE;
    final ParserCursor cursor = new ParserCursor(0, s.length());
    final List<NameValuePair> list = new ArrayList<>();
    while (!cursor.atEnd()) {
        final String name = tokenParser.parseToken(s, cursor, QUERY_PARAM_SEPARATORS);
        String value = null;
        if (!cursor.atEnd()) {
            final int delim = s.charAt(cursor.getPos());
            cursor.updatePos(cursor.getPos() + 1);
            if (delim == PARAM_VALUE_SEPARATOR) {
                value = tokenParser.parseToken(s, cursor, QUERY_VALUE_SEPARATORS);
                if (!cursor.atEnd()) {
                    cursor.updatePos(cursor.getPos() + 1);
                }
            }
        }
        if (!name.isEmpty()) {
            list.add(new BasicNameValuePair(PercentCodec.decode(name, charset, plusAsBlank), PercentCodec.decode(value, charset, plusAsBlank)));
        }
    }
    return list;
}
Also used : ParserCursor(org.apache.hc.core5.http.message.ParserCursor) NameValuePair(org.apache.hc.core5.http.NameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) BasicNameValuePair(org.apache.hc.core5.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Tokenizer(org.apache.hc.core5.util.Tokenizer)

Example 48 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class TestHeaderElement method testConstructor3.

@Test
public void testConstructor3() throws Exception {
    final HeaderElement element = new BasicHeaderElement("name", "value", new NameValuePair[] { new BasicNameValuePair("param1", "value1"), new BasicNameValuePair("param2", "value2") });
    Assertions.assertEquals("name", element.getName());
    Assertions.assertEquals("value", element.getValue());
    Assertions.assertEquals(2, element.getParameters().length);
    Assertions.assertEquals("value1", element.getParameterByName("param1").getValue());
    Assertions.assertEquals("value2", element.getParameterByName("param2").getValue());
}
Also used : HeaderElement(org.apache.hc.core5.http.HeaderElement) Test(org.junit.jupiter.api.Test)

Example 49 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class TestNameValuePair method testNameNotEqual.

@Test
public void testNameNotEqual() throws Exception {
    final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
    final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", "value");
    Assertions.assertNotEquals(NameValuePair, NameValuePair2);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) Test(org.junit.jupiter.api.Test)

Example 50 with NameValuePair

use of org.apache.hc.core5.http.copied.NameValuePair in project httpcomponents-core by apache.

the class TestNameValuePair method testValueNotEqual.

@Test
public void testValueNotEqual() throws Exception {
    final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
    final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value2");
    Assertions.assertNotEquals(NameValuePair, NameValuePair2);
    final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
    final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "VALUE");
    Assertions.assertNotEquals(NameValuePair3, NameValuePair4);
    final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "VALUE");
    final NameValuePair NameValuePair6 = new BasicNameValuePair("name", "value");
    Assertions.assertNotEquals(NameValuePair5, NameValuePair6);
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) Test(org.junit.jupiter.api.Test)

Aggregations

NameValuePair (org.apache.hc.core5.http.NameValuePair)56 Test (org.junit.jupiter.api.Test)26 BasicNameValuePair (org.apache.hc.core5.http.message.BasicNameValuePair)25 ArrayList (java.util.ArrayList)15 URI (java.net.URI)13 UrlEncodedFormEntity (org.apache.hc.client5.http.entity.UrlEncodedFormEntity)12 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)11 Map (java.util.Map)10 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)9 IOException (java.io.IOException)7 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)7 URIBuilder (org.apache.hc.core5.net.URIBuilder)7 URISyntaxException (java.net.URISyntaxException)6 HashMap (java.util.HashMap)5 HeaderElement (org.apache.hc.core5.http.HeaderElement)5 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)4 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)4 List (java.util.List)3 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)3 HttpEntity (org.apache.hc.core5.http.HttpEntity)3