0

I woudlike to put some parameter in my request (code value and name value) :

    String code = "001";
    String name = "AAA";       

    HttpGet request = new HttpGet(url);
    String auth = user + ":" + mdp;

    byte[] encodedAuth = Base64.encodeBase64(
            auth.getBytes(StandardCharsets.ISO_8859_1));

    String authHeader = "Basic " + new String(encodedAuth);

    request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(request);

    int statusCode = response.getStatusLine().getStatusCode();

How can I do this with authentification request ?

Something like : code=001&name=AAA in the URL

Software14
  • 155
  • 1
  • 9

1 Answers1

0

Use a URIBuilder to construct your URL

import org.apache.http.client.utils.URIBuilder;
//...
final String URI_PARAM_CODE = "code";
final String URI_PARAM_NAME = "name";

String code = "001";
String name = "AAA";

URI uri = new URIBuilder("http://google.com")
    .setParameter(URI_PARAM_CODE, code)
    .setParameter(URI_PARAM_NAME, name)
    .build();

You can also set other useful attributes before calling URIBuilder::build - please refer to Apache URIBuilder documentation.

Dropout
  • 13,653
  • 10
  • 56
  • 109