/ / Vertx HttpClient getNow nie działa - java, http, vert.x, vertx-httpclient

Vertx HttpClient getNow nie działa - java, http, vert.x, vertx-httpclient

Mam problem z vertt HttpClient. Oto kod, który pokazuje, że testy GET używają vertx i plain java.

    Vertx vertx = Vertx.vertx();
HttpClientOptions options = new HttpClientOptions()
.setTrustAll(true)
.setSsl(false)
.setDefaultPort(80)
.setProtocolVersion(HttpVersion.HTTP_1_1)
.setLogActivity(true);
HttpClient client = vertx.createHttpClient(options);

client.getNow("google.com", "/", response -> {
System.out.println("Received response with status code " + response.statusCode());
});
System.out.println(getHTML("http://google.com"));

Skąd getHTML () pochodzi stąd: Jak wykonać HTTP GET w Javie?

Oto moje wyniki:

<!doctype html><html... etc <- correct output from plain java
Feb 08, 2017 11:31:21 AM io.vertx.core.http.impl.HttpClientRequestImpl
SEVERE: java.net.UnknownHostException: failed to resolve "google.com".     Exceeded max queries per resolve 3

Ale vertx nie może się połączyć. Co tu jest nie tak? Nie używam żadnego proxy.

Odpowiedzi:

0 dla odpowiedzi № 1

Oto przykładowy kod, który działa dla mnie.

public class TemplVerticle extends HttpVerticle {

public static void main(String[] args) {
Vertx vertx = Vertx.vertx();

// Create the web client and enable SSL/TLS with a trust store
WebClient client = WebClient.create(vertx,
new WebClientOptions()
.setSsl(true)
.setTrustAll(true)
.setDefaultPort(443)
.setKeepAlive(true)
.setDefaultHost("www.w3schools.com")

);


client.get("www.w3schools.com")

.as(BodyCodec.string())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<String> response = ar.result();
System.out.println("Got HTTP response body");
System.out.println(response.body().toString());

} else {
ar.cause().printStackTrace();
}
});
}

}