-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Client.java
34 lines (28 loc) · 1.11 KB
/
Client.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package io.vertx.example.core.http.https;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpMethod;
/*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class Client extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", Client.class.getName());
}
@Override
public void start() throws Exception {
// Note! in real-life you wouldn't often set trust all to true as it could leave you open to man in the middle attacks.
HttpClientOptions options = new HttpClientOptions().setSsl(true).setTrustAll(true);
HttpClient client = vertx.createHttpClient(options);
client.request(HttpMethod.GET, 4443, "localhost", "/")
.compose(req -> req.send()
.compose(resp -> {
System.out.println("Got response " + resp.statusCode());
return resp.body();
})).onSuccess(body -> {
System.out.println("Got data " + body.toString("ISO-8859-1"));
}).onFailure(Throwable::printStackTrace);
}
}