Vertx WebClient 下载文件
Vertx WebClient download file
正在尝试使用 Vertx WebClient 从这个 url 下载文件,但无法正常工作。我在这里遗漏了什么吗?
// 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());
}
});
既然我想出来了,就在这里回答这个问题。
问题是网站重定向到不同的下载 url 但 Vertx WebClient
未来没有完成。它至少应该有 return 状态代码 302 来说明原因 - 唉!
正在尝试使用 Vertx WebClient 从这个 url 下载文件,但无法正常工作。我在这里遗漏了什么吗?
// 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());
}
});
既然我想出来了,就在这里回答这个问题。
问题是网站重定向到不同的下载 url 但 Vertx WebClient
未来没有完成。它至少应该有 return 状态代码 302 来说明原因 - 唉!