1

我有一个 https 请求,它的 uri 以大写字母开头。我已经在邮递员中对其进行了测试,并得到了响应;但是在我的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?

4

1 回答 1

1

我找到了答案!我使用io.vertx.ext.web.client的WebClient来创建一个 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 不会有任何更改或转换。

于 2021-12-04T18:31:37.343 回答