簡體   English   中英

添加編解碼器以在WebClient中的請求中添加內容長度

[英]Adding Codec to Add Content-Length in my Requests in WebClient

我想將某種ChannelOutboundHandler添加到接收請求的WebClient ,向其中添加“ Content-Length ”標頭,然后轉發。 我知道該類HttpContentEncoder做到這一點。 如何在WebClient配置此類?

如果只想添加Content-Length ,則不需要任何處理程序。 您可以這樣做:

String requestBody = "something";
String response =
        WebClient.create()
                .post()
                .uri("https://postman-echo.com/post")
                .contentLength(9)
                .body(BodyInserters.fromObject(requestBody))
                .retrieve()
                .bodyToMono(String.class)
                .block();
System.out.println(response);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM