EFOE EFOE - 1 year ago 165
reST (reStructuredText) Question

Error using httpclient on vertx

Hello i'm trying to perform a rest call on a distant ressources using the code bellow. on vertx 3.3.3 it works with defaulthttpclient (appache) but it's not asynchron

i still get the error:
nov. 01, 2016 8:15:08 AM io.vertx.core.http.impl.HttpClientRequestImpl
GRAVE: java.net.ConnectException: Connection refused: localhost/

final HttpClient httpClient = vertx.createHttpClient();

final HttpGet getRequest = new HttpGet(uri);

httpClient.request(apiMethod.getHttpMethod(), uri, resultHandler -> {
if (resultHandler.statusCode() == 200) {
} else {
resultHandler.bodyHandler(buffer -> {
String message = "";
logger.debug("Output from Server .... \n");
message = buffer.toString();
apiMethod.setCallingDate(new Date());
}).putHeader("content-type", "application/json").end();

Can anyone help?

Best regards,

Answer Source

It seems you're forgetting to configure the client to which host and port to connect to and it is using the default values localhost:80 as you can read from the exception.

You should be doing something like:

httpClient.request(GET, "www.yourserver.com", 80, uri, res -> {

Note that uri is not an URL so it should be something like:


If you're looking for a more compact version then what you should be using is the requestAbs method:

  .requestAbs(GET, "http://www.yourserver.com/api/users?from=5&to=10", res -> {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download