在Spring中,如何使用WebClient发布到URL?

问题描述 投票:0回答:1

现在,我有一个表示JSON对象的类Message。>

@Value
@Builder
public class Message {

    @JsonProperty("@msgType")
    String msgType;
    @JsonProperty("@type")
    String type;
    String category;
    @Singular("characteristic") List<CharacteristicItem> characteristic;
    @Singular("receiver") List<ReceiverItem> receiver;
    Sender sender;

}

我想将Message类的实例作为JSON发送到远程URL https:example.com/message。如何创建可以使用JSON POST到此URL的方法?注意,我不是在创建映射,我只是想发布到URL并检索HTTP响应并转换为字符串。我正在考虑使用WebClient。请注意,我只想查看响应是否为200、400等,所以不需要处理响应JSON。

[现在,我有一个类Message,它表示一个JSON对象,因此@Value @Builder公共类Message {@JsonProperty(“ @ msgType”)字符串msgType; @JsonProperty(“ @ type”)字符串类型; ...

spring http post webclient
1个回答
0
投票

如果要使用WebClient,则可以编写以下代码以将JSON数据发布到URL并检索响应状态代码。

© www.soinside.com 2019 - 2024. All rights reserved.