我不能使用WebClient对rest服务进行先行调用。我只想在需要时读取count头,以便在后续的rest调用中使用相同的头,如何实现相同的目的?如何将Mono>转换为整数计数值?GET调用是成功的,但是HEAD调用总是失败,我使用以下代码:
private void getResultCount(WebClient webClient)
{
Mono<ClientResponse> response = webClient.head()
.uri("/rest/v2/electronics/products/search/?query=::category:575:")
.exchange()
.doOnSuccess(clientResponse -> System.out.println("clientResponse.headers() = " + clientResponse.headers()));
System.out.println("response "+response);
}发布于 2021-02-11 01:55:03
我认为您所问的是如何从Head调用中提取信息,当它的响应在HEADERS中而不是body中时,我需要类似的东西,一段时间后我找到了这个baeldung article
我的解决方案是:
var aHeader = aClient.head()
.retrieve()
.toEntity(String.class)
.map(aResponse -> aResponse.getHeaders())
.block();
System.out.println(aHeader);https://stackoverflow.com/questions/51045599
复制相似问题