首页 > 解决方案 > 如何使用 Spring Boot WebClient 通过发布请求发送多个值?

问题描述

如您所见,在我的服务层中,此方法使用 Spring Boot WebClient 框架向服务器发送类似客户端的 post 请求,但我遇到了一个问题,正如您所看到的,我的方法接受 4 个参数,您看到了并且我想要仅将这 3 个参数发送到服务器。我想知道如何设置多个参数以使用 WebClient 发送?什么方法支持这个?

@Override
public Mono<ResponseEntity<? extends ResponseResource>> sendSms(String message, List<BulkSmsRequestResource> request, String originatorName, String sendSmsApi) {
    if (request == null) {
        return Mono.just(new ResponseEntity<>(
                new ErrorResponseResource(
                        "Transaction failed successfully!",
                        400),
                HttpStatus.BAD_REQUEST));
    }
    Mono<BulkSmsRequestResource> bulkSmsRequestResourceMono = webClientBuilder.build()
            .post()
            .uri(sendSmsApi)
            .body(Mono.just(request), BulkSmsRequestResource.class)
            .retrieve()
            .bodyToMono(BulkSmsRequestResource.class);
    bulkSmsRequestResourceMono.subscribe();
    return Mono.just((new ResponseEntity<>(new SuccessResponseResource("Transaction done successfully", 200), HttpStatus.OK)));
}

标签: javaspring-bootrestclientwebclient

解决方案


推荐阅读