I\'m using the Apache HttpClient 4 and it works fine. The only thing that doesn\'t work is custom ports. It seems like the root directory is fetched and the port is ignored.
Another approach is to configure httpClient
to use a custom SchemaPortResolver
.
int port = 8888;
this.httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
.setDefaultCredentialsProvider(authenticator.authenticate(url,
port, username, password))
.setSchemePortResolver(new SchemePortResolver() {
@Override
public int resolve(HttpHost host) throws UnsupportedSchemeException {
return port;
}
})
.build();
This way, you avoid problems of using a String to construct a HttpPost
and calling httpClient.execute(host, httpPost, handler, context)
, only finding your port is appended after the path, like: http://localhost/api:8080
, which is wrong.