我有一个 https 请求,其 uri 以大写字母开头。我已经在 postman 中进行了测试,并得到了回复;但在我的 vertx (io.vertx.core) 代码中,我无法获得所需的响应响应。看来目标服务器拒绝了我。 看来我想要的 uri 自动更改为小写。不幸的是,服务器不接受更改后的模式。
所需的 uri :/Internalservice
https://example.com/Internalservice
我使用这个webClient:io.vertx.ext.web.client;
这是我的方法:
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[]{}));
}
我必须做什么来处理这个区分大小写的 uri?
最佳答案
我已经找到答案了! 我已经使用 io.vertx.ext.web.client 的 WebClient 来创建 http post 请求。 有一个方法:HttpRequest postAbs(String AbsoluteURI) 在其纪录片中我们有:
/**
* 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
*/
所以它帮助了我!
我的方法是:
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[]{}));
}
如您所见,参数与以前的版本不同。
现在我可以输入 https://example.com/Internalservice
作为绝对 uri。所需的 uri 不会发生任何更改或转换。
关于java - 在区分大小写模式下创建带有 uri 的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70175287/