【问题标题】:Vert.x WebClient - GET request over HTTPS fails on Ubuntu server with null causeVert.x WebClient - 通过 HTTPS 的 GET 请求在 Ubuntu 服务器上失败,原因为空
【发布时间】:2017-11-07 21:22:01
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

  • 尝试“信任所有人”?此外,尝试连接调试器以深入了解根本原因(例如,可能是密码问题)
  • @opyate clientOptions.setTrustAll(true); 没有区别,-Djavax.net.debug=all 也一样。而且它不安全。我正在寻找setTrustOptions 文档。希望远程调试能帮到我。
  • @opyate 对-Djavax.net.debug=all 做了重要的事情:系统属性 jdk.tls.client.cipherSuites 设置为 'null' 系统属性 jdk.tls.server.cipherSuites 设置为 'null ' 在服务器启动时。

标签: java ssl https vert.x


【解决方案1】:

试试这个:

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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 2021-01-18
    • 1970-01-01
    • 2014-02-14
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多