我正在尝试使用Vert.x Web客户端3.5.0
(和Java 8)通过HTTPS发送GET请求。
Vertx vertx = Vertx.vertx();
WebClientOptions clientOptions = new WebClientOptions();
WebClient webClient = WebClient.create(vertx, clientOptions);
Handler<AsyncResult<HttpResponse<Buffer>>> testHandler = asyncResult -> {
System.out.println("async = " + asyncResult);
System.out.println("async result = " + asyncResult.result());
System.out.println("async failed = " + asyncResult.failed());
System.out.println("async succeeded = " + asyncResult.succeeded());
System.out.println("async cause = " + asyncResult.cause());
};
webClient.get(443, "oauth.vk.com", "/access_token").
addQueryParam("client_id", appId).
addQueryParam("client_secret", secureKey).
addQueryParam("v", apiVersion)
addQueryParam("grant_type", "client_credentials").
ssl(true).
send(testHandler);
它适用于我的本地计算机(Windows 10),但在Ubuntu(17.04 x64
)服务器上失败。 asyncResult.failed()
是true
。但asyncResult.cause()
为null
。
我使用cURL进行了测试,效果很好;看起来像Vert.x和OpenSSL交互的问题。
这是我Maven的POM文件的摘录:
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>3.5.0</version>
</dependency>
答案 0 :(得分:0)
试试这个:
Vertx.vertx().createHttpClient().get(new RequestOptions().setSsl(true).setHost("oauth.vk.com").setPort(443).setURI("/access_token"),
res -> {
System.out.println("result: " + res.statusCode() + " " + res.statusMessage());
res.bodyHandler(body -> {
System.out.println("result body: " + body.toString());
});
}).end();