Vertx WebClient download file

1.6k views Asked by At

Trying to download a file from this url using Vertx WebClient but not working. Am I missing something here?

    // Create the web client and enable SSL/TLS with a trust store
    WebClient client = WebClient.create(vertx,
            new WebClientOptions()
                    .setSsl(false)
                    .setTrustAll(true)
                    .setDefaultPort(80)
                    .setKeepAlive(true)
                    .setDefaultHost("www.nasdaq.com"));


    client.get(80, "www.nasdaq.com", "/screening/companies-by-industry.aspx")
            .addQueryParam("exchange", "NASDAQ")
            .addQueryParam("render", "download")
            .putHeader("content-type","text/csv")
            .as(BodyCodec.string())
            .send(ar -> {
                if (ar.succeeded()) {

                    // HttpResponse<Void> response = ar.result();

                    System.out.println("Received response with status code");
                } else {
                    System.out.println("Something went wrong " + ar.cause().getMessage());
                }
            });
1

There are 1 answers

0
Philip K. Adetiloye On BEST ANSWER

Answer the question here since I figured it out.

The problem is the website redirects to a different download url but the Vertx WebClient future did not complete. It should've at least return a status code 302 to indicate why - sigh!