java - 在区分大小写模式下创建带有 uri 的 http 请求

标签 java https vert.x vertx-httpclient

我有一个 https 请求,其 uri 以大写字母开头。我已经在 postman 中进行了测试,并得到了回复;但在我的 vertx (io.vertx.core) 代码中,我无法获得所需的响应响应。看来目标服务器拒绝了我。 看来我想要的 uri 自动更改为小写。不幸的是,服务器不接受更改后的模式。

所需的 uri :/Internalservice

https://example.com/Internalservice

我使用这个webClient:io.vertx.ext.web.client;

这是我的方法:

    public CompletionStage<HttpResponse> post(String host, int port, String uri, MultiMap headers, JsonObject body) {
        return client.post(port, host, uri)
                .putHeaders(headers)
                .timeout(requestTimeout.toMillis())
                .sendJsonObject(body)
                .toCompletionStage()
                .thenApply(response -> new HttpResponse(response.statusCode(), response.body() != null ?     response.body().getBytes() : new byte[]{}));
    }

我必须做什么来处理这个区分大小写的 uri?

最佳答案

我已经找到答案了! 我已经使用 io.vertx.ext.web.clientWebClient 来创建 http post 请求。 有一个方法:HttpRequest postAbs(String AbsoluteURI) 在其纪录片中我们有:

 /**
   * Create an HTTP POST request to send to the server using an absolute URI, specifying a response handler to receive
   * the response
   * @param absoluteURI  the absolute URI
   * @return  an HTTP client request object
   */

所以它帮助了我!

我的方法是:

public CompletionStage<HttpResponse> post(String uri, MultiMap headers, JsonObject body) {
    return client.postAbs(uri)
            .putHeaders(headers)
            .timeout(requestTimeout.toMillis())
            .sendJsonObject(body)
            .toCompletionStage()
            .thenApply(response -> new HttpResponse(response.statusCode(), response.body() != null ? response.body().getBytes() : new byte[]{}));
}

如您所见,参数与以前的版本不同。 现在我可以输入 https://example.com/Internalservice 作为绝对 uri。所需的 uri 不会发生任何更改或转换。

关于java - 在区分大小写模式下创建带有 uri 的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70175287/

相关文章:

java - Schematron 的 Uri

java - 如何在 Dockerized Spring Boot 应用程序中启用 https(未找到 PKCS12)

java - 等待 vertx 中多个可观察对象的响应

java - 如何将库添加到Vert.x的FatJar中?

JavaMail Message.reply(boolean) 不填充收件人

java - 使用触发器删除 Oracle 表中的行

java - 如何使 Simple 不序列化空 ArrayList?

css - HTTPS ssl 证书 WebView 和 CSS

php - 我的应用程序缓存 list 测试有什么问题?

java - 多线程 Vert.x 每秒处理数千个连接