javahttpsvert.xvertx-httpclient

Create a http request with a uri in Case sensitive mode


I have a https request which its uri begins with capital letter. I have tested it in postman and i have gotten response; But in my code by vertx (io.vertx.core), I can not get desired response response. It seems that destination server reject me. It seems that my desired uri changes to lowercase automatically. Unfortunately the server does not accept the changed mode.

Desired uri : /Internalservice

https://example.com/Internalservice

I use this webClient: io.vertx.ext.web.client;

This is my method:

    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[]{}));
    }

what I have to do to handle this case sensitive uri?


Solution

  • I have found the answer! I have used of WebClient of io.vertx.ext.web.client to create a http post request. There is a method: HttpRequest postAbs(String absoluteURI) Which in its documentary we have:

     /**
       * 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
       */
    

    so it helped me!

    my method is:

    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[]{}));
    }
    

    as you see the arguments are different from the previous version. Now I can enter https://example.com/Internalservice as the absolute uri. There will be no changes or conversion in desired uri.