英文:
vertx post call search domain query failed
问题
我创建了一个 Web 客户端如下:
WebClientOptions options = new WebClientOptions();
WebClient client = WebClient.create(vertx, options);
String host = "https://example.com/";
我正试图进行一个 JSON 命令的 POST 调用,如下:
client.post(8080, host, "/api/executor/command")
.ssl(false)
.rxSendJson(jsonCmd)
.map((HttpResponse<Buffer> r) -> {
System.out.println("响应: " + r.bodyAsString());}).toObservable();})
.doOnError(error -> System.err.println("错误信息: " + error.getMessage()))
但是我得到了这个错误:
错误信息: 搜索域查询失败。原始主机名: 'https://example.com/' 在经过 3 次查询后无法解析为 'https://example.com/.lan'
而在终端上进行相同的 curl 调用如下:
curl https://example.com/api/executor/command -XPOST --insecure -d 'jsonCmd';
我没有收到任何错误并且服务器回复了我。
我做错了什么?我是 vertx/java 的新手。
谢谢
Matteo
编辑
我按建议添加了选项
options.setTrustAll(true);
并且移除了 println,现在似乎工作了,谢谢。。
英文:
I have created an webClient as:
WebClientOptions options = new WebClientOptions();
WebClient client = WebClient.create(vertx, options);
String host = "https://example.com/";
and I am trying to do a POST call of a json command as:
client.post(8080, host, "/api/executor/command")
.ssl(false)
.rxSendJson(jsonCmd)
.map((HttpResponse<Buffer> r) -> {
System.out.println("response: " + r.bodyAsString());}).toObservable();})
.doOnError( error -> System.err.println("The error message is: " + error.getMessage()))
But I get this error:
The error message is: Search domain query failed. Original hostname: 'https://example.com/' failed to resolve 'https://example.com/.lan' after 3 queries
While doing the same curl call on the terminal as:
curl https://example.com/api/executor/command -XPOST --insecure -d 'jsonCmd'
I don't get any error and the server responds me.
What am I doing wrong? I am a newby of vertx/java.
Thanks
Matteo
EDIT
I have added as recommended the options
options.setTrustAll(true);
and removed the println and now it seems to work, thanks..
答案1
得分: 3
你使用cURL将查询通过ssl(如HTTPS所示,443是默认的HTTPS端口)发布到端口443。
然而,您不仅禁用了ssl(使用ssl(false)
),还使用了错误的端口号和错误的主机名(您提供了带有https://
前缀的URL,主机名不会包含该前缀)。您的代码应该像这样:
String host = "example.com";
client.post(443, host, "/api/executor/command")
.ssl(true)
...等等...
这样它就能与cURL的操作相匹配。
英文:
You post your query with cURL to port 443 using ssl (as HTTPS suggests, 443 is default HTTPS port).
Whereas you not only disable ssl (by using ssl(false)
), but also using wrong port number and wrong hostname (you give URL instead of hostname, hostname wouldn't contain https://
prefix). Your code should be like:
String host = "example.com";
client.post(443, host, "/api/executor/command")
.ssl(true)
...and so on...
so that it matches what cURL is doing.
答案2
得分: 2
除了Demitry已经说的之外,由于map()返回void,所以无法将其映射到println,因此在我看来,这段代码片段不会编译,所以我认为你漏掉了一些内容。
但主要是由于ssl和port设置错误导致失败。如果你不想让客户端验证证书,将setTrustAll
选项设置为true。
它将与您的curl命令中的--insecure
执行相同的操作。
英文:
Next to what demitry already said you can't map() to a println due to it returning void so to me this code snippet won't compile so I think you've missed something there.
But mainly it fails due to ssl and port being wrong. Set the options for setTrustAll
tot true if you don't want the client to verify the certificate(s).
It will do the same thing as in your curl command with --insecure
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论