【发布时间】:2019-11-04 05:04:39
【问题描述】:
我想实现 WebFlux 示例客户端,它可以使用 http 参数发出请求并获取响应正文和 http 响应代码。我试过这个:
public ClientResponse execute(NotificationMessage nm)
Mono<String> transactionMono = Mono.just(convertedString);
return client.post().uri(builder -> builder.build())
.header(HttpHeaders.USER_AGENT, "agent")
.body(transactionMono, String.class).exchange().block();
}
private static String convert(Map<String, String> map) throws UnsupportedEncodingException {
String result = map.entrySet().stream().map(e -> encode(e.getKey()) + "=" + encode(e.getValue()))
.collect(Collectors.joining("&"));
return result;
}
private static String encode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
您能否在.exchange() 之后给我一些建议,如何获取 http 状态代码和所有可用的正文。
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-webflux