订阅发送时请求未发送

时间:2019-10-13 21:15:15

标签: java spring spring-webflux

我正在尝试使用以下代码实现POST请求:

public void testImpl() throws JAXBException {

        WebClient webClient = WebClient.create();
        webClient.post()
        .uri("https://webhook.site/a6ad3a35-61c6-4bfc-8d8c-7e5a3e2462aa")
        .retrieve()
        .onStatus(HttpStatus::is4xxClientError, response -> {
              return Mono.error(new MyCustomConnectionException());
         })
        .onStatus(HttpStatus::is5xxServerError, response -> {
            return Mono.error(new MyCustomConnectionException());
         })
        .bodyToMono(String.class)
        .subscribe();
    }

    class MyCustomConnectionException implements Supplier<Throwable> {

        @Override
        public Throwable get() {
            // TODO Auto-generated method stub
            return null;
        }

    }

但是由于某些原因,网站webhook.site中没有列出任何请求,您知道我该如何解决此问题?

PS。我也尝试了这个但没有成功:

Mono<String> transactionMono = Mono.just("wfw");

        WebClient webClient = WebClient.create("https://webhook.site");
        Mono<String> flux = webClient.post()
        .uri("/a6ad3a35-61c6-4bfc-8d8c-7e5a3e2462aa")
        .body(transactionMono, String.class)
        .retrieve()
        .onStatus(HttpStatus::is4xxClientError, response -> {
              return Mono.error(new MyCustomConnectionException());
         })
        .onStatus(HttpStatus::is5xxServerError, response -> {
            return Mono.error(new MyCustomConnectionException());
         })
        .bodyToMono(String.class);


        Disposable subscription = flux.subscribe(str -> process(str));

        subscription.dispose();

0 个答案:

没有答案