我正在尝试将Flux从Webclient发布到服务器,并且我总是得到空的请求正文。
路由器:
@Bean
public RouterFunction<ServerResponse> procces(LetterHandler handler){
return RouterFunctions.route(POST("/letter").and(accept(APPLICATION_STREAM_JSON)).and(contentType(APPLICATION_STREAM_JSON)), handler::handle);
}
处理程序方法:
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
serverRequest.body(toFlux(Letter.class)).doOnEach(letterSignal -> System.out.println(letterSignal)).switchIfEmpty(subscriber -> System.out.println("empty")).subscribe();
//serverRequest.bodyToFlux(Letter.class).doOnEach(letterSignal -> System.out.println(letterSignal)).subscribe();
}
WebClient字段:
private final WebClient webClient = WebClient.builder()
.baseUrl("http://localhost:8081")
// .defaultHeader(MediaType.APPLICATION_JSON_VALUE)
.build();
WebClient-请求:
public void send(Flux letters) {
webClient.post().uri("/letter")
.accept(MediaType.APPLICATION_STREAM_JSON)
.contentType(MediaType.APPLICATION_STREAM_JSON)
.body(letters, Letter.class)
//.body(BodyInserters.fromObject(letter))
// .retrieve().bodyToMono(void.class).subscribe();
.exchange().subscribe();
}
为什么我总是收到空请求?我将不胜感激任何帮助。 预先感谢!