Vertx无法解析主机,也无法使用Web客户端下载大文件



我试图从服务器下载文件,但收到错误

检查了一些解决方案,我发现需要禁用dnsressolver,但这也不适用于我。

以下是禁用dnsresresolver 的代码

System.setProperty("vertx.disableDnsResolver", "true");

源代码:-

WebClientOptions webClientOptions = new WebClientOptions() .setSsl(true)
.setTrustAll(true)
.setDefaultPort(443)
.setKeepAlive(true);
WebClient webClient = WebClient.create(vertx,webClientOptions);
final HttpRequest<Buffer> abs = webClient.get("https://downloads.dell.com","/xyz.exe");
abs.send(responseHandler ->{
if (responseHandler.succeeded()){
String temp = vertx.fileSystem().createTempFileBlocking("", "");
vertx.fileSystem().writeFileBlocking(temp, responseHandler.result().body());
routingContext.response().end("Success");
}else{
log.error("Error: {}",responseHandler.cause());
routingContext.response().end("failure");
}
});

这里有一个例外:-

java.net.UnknownHostException: failed to resolve 'https://downloads.dell.com'. Exceeded max queries per resolve 4 
at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:927) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:886) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:358) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:858) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:358) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:858) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:358) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:858) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:358) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:1001) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:878) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:358) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]
at io.netty.resolver.dns.DnsResolveContext.onResponse(DnsResolveContext.java:545) [netty-resolver-dns-4.1.49.Final.jar:4.1.49.Final]

更新:-使用getAbs((我可以下载大约15到20 mb的文件,但在文件大小超过500 mb的情况下无法下载

WebClient.get(String, String)方法需要一个主机名和一个路径,但您提供了一个URL作为第一个参数。

如果要使用URL,请使用WebClient.getAbs(String)方法:

final HttpRequest<Buffer> abs = webClient.getAbs("https://downloads.dell.com/xyz.exe");

它对我来说解决得很好

fun main() {
val vertx = Vertx.vertx()
val webClientOptions = WebClientOptions().setSsl(true)
.setTrustAll(true)
.setDefaultPort(443)
.setKeepAlive(true)
val webClient = WebClient.create(vertx, webClientOptions)
val abs = webClient.getAbs("https://downloads.dell.com/xyz.exe")
abs.send().onComplete { println(it.failed()) }.onSuccess { println(it.statusMessage()) }
}
// prints
// false
// Not Found

相关内容

  • 没有找到相关文章

最新更新