首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Spring-Webflux将JSON发送到PUT端点

如何使用Spring-Webflux将JSON发送到PUT端点
EN

Stack Overflow用户
提问于 2021-06-19 02:10:51
回答 1查看 80关注 0票数 0

我正在尝试使用webflux将json字符串发送到put端点。

例如,假设我试图到达的终点是http://etc:99999/put/here,我的代码如下所示:

代码语言:javascript
复制
@Service
public class someService {
  private final WebClient webClient;

  public someService(WebClient.Builder webClientBuilder) {
    this.webClient = webClientBuilder.baseUrl("http://etc:9999999/").build();
  }
  
  public Mono<Void> sendPut(String someMessage) {
      return webClient.put()
                    .uri("put/here")
                    .contentType(MediaType.APPLICATION_JSON)
                    .bodyValue(someMessage)
                    .retrieve();
  }
}

然而,这似乎根本没有触及端点。我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2021-06-19 04:03:56

问题是没有任何东西订阅我的web客户端。即

代码语言:javascript
复制
Mono<void> putStream = webClient.put()
                        .uri("put/here")
                        .contentType(MediaType.APPLICATION_JSON)
                        .bodyValue(someMessage)
                        .retrieve()
                        .bodyToMono();

不会发送put请求。

但是-

代码语言:javascript
复制
Mono<void> putStream = webClient.put()
                        .uri("put/here")
                        .contentType(MediaType.APPLICATION_JSON)
                        .bodyValue(someMessage)
                        .retrieve()
                        .bodyToMono();

putStream.subscribe();

将要。

下面是Reactor文档中帮助我解决这个问题的相关部分:Reactor Docs

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68039756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档