Post 参数到 http link

Post params into http link

我想用 webflux 实现示例,它将参数发送到 http link:

String convertedString = "key=value&key=value";

    Mono<String> transactionMono = Mono.just(convertedString);
            return client.post().uri("http://www.some_host.com/receive.php")
                    .header(HttpHeaders.USER_AGENT, "Mozilla/5.0")
                    .accept(MediaType.APPLICATION_XML)
                    // .contentType(MediaType.APPLICATION_XML)
                    .body(transactionMono, String.class)
                    .retrieve()
                    .bodyToMono(NotificationEchoResponse.class);

请求应如下所示:http://www.some_host.com/receive.php?key=value&key=value

实现这个的正确方法是什么?

你走在正确的轨道上。但是,参数不是正文的一部分,而是URI的一部分。

您的代码应如下所示:

String convertedString = "key=value&key=value";

return client.post().uri("http://www.some_host.com/receive.php?" + convertedString)
        .header(HttpHeaders.USER_AGENT, "Mozilla/5.0")
        .accept(MediaType.APPLICATION_XML)
        // .contentType(MediaType.APPLICATION_XML)
        .retrieve()
        .bodyToMono(NotificationEchoResponse.class);