VERTX HTTP请求的奇怪问题

发布于 2025-02-08 20:09:15 字数 933 浏览 0 评论 0原文

我在AWS上配置了HTTPS网站,该网站允许从IP的白色列表中访问。 我的本地机器以VPN连接在白色列表中运行。 我可以从Web浏览器或Java.net.http软件包访问该网站,并带有以下代码:

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://mywebsite/route"))
    .GET() // GET is default
    .build();
HttpResponse<Void> response = client.send(request,
    HttpResponse.BodyHandlers.discarding());

但是,如果我从io.vertx.ext.web.client软件包中替换了代码,我得到了403的禁止响应来自同一网站。

WebClientOptions options = new WebClientOptions().setTryUseCompression(true).setTrustAll(true);
HttpRequest<Buffer> request = WebClient.create(vertx, options)
            .getAbs("https://mywebsite/route")
            .ssl(true).putHeaders(headers);
request.send(asyncResult -> {
      if (asyncResult.succeeded()) {
            HttpResponse response = asyncResult.result();
      }
});

有人知道为什么VERTX实现被拒绝吗?

I configured an HTTPS website on AWS, which allows visiting from a white list of IPs.
My local machine runs with a VPN connection, which is in the white list.
I could visit the website from web browser or by the java.net.http package with the below code:

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://mywebsite/route"))
    .GET() // GET is default
    .build();
HttpResponse<Void> response = client.send(request,
    HttpResponse.BodyHandlers.discarding());

But if I replaced the code with a Vertx implementation from io.vertx.ext.web.client package, I got a 403 forbidden response from the same website.

WebClientOptions options = new WebClientOptions().setTryUseCompression(true).setTrustAll(true);
HttpRequest<Buffer> request = WebClient.create(vertx, options)
            .getAbs("https://mywebsite/route")
            .ssl(true).putHeaders(headers);
request.send(asyncResult -> {
      if (asyncResult.succeeded()) {
            HttpResponse response = asyncResult.result();
      }
});

Does anyone have an idea why the Vertx implementation is rejected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2025-02-15 20:09:15

终于有根本原因。我启动了一个本地服务器,该服务器接受测试请求并将其转发到AWS上的服务器。测试客户端将请求发送到Localhost,因此在请求标题中“ host = localhost:8080/...”。在Vert.x实施中,将错误的标题输入“ host = localhost:443/...”被错误地放入请求标题中。我没有调试Vert.x实现,所以我不知道为什么它会这样做。但是随后,AWS防火墙拒绝了该请求,该请求的规则是请求不能来自Localhost。

Finally got the root cause. I started a local server that accepts the testing request and forwards it to the server on AWS. The testing client sent the request to localhost and thus "Host=localhost:8080/..." is in the request header. In the Vert.X implementation, a new header entry "Host=localhost:443/..." is wrongly put into the request headers. I haven't debug the Vert.X implementation so I have no idea why it behaviors as this. But then the AWS firewall rejected the request with a rule that a request could not come from localhost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文