我的问题是,当我try 这一点时,我得到了一个媒体类型错误,然后我更改了标题.现在我收到一个500错误.问题不在于api,它在postman上运行得很好,我在请求帖子时是否在代码中出错?
我的对象模型
private String module;
private String notificationGroupType;
private String notificationGroupCode;
private String notificationType;
private String inLineRecipients;
private String eventCode;
private HashMap<String, Object> metaData;
public EmailModel() {
this.module = "CORE";
this.notificationGroupType ="PORTAL";
this.notificationGroupCode = "DEFAULT";
this.notificationType = "EMAIL";
this.inLineRecipients ="[chrispotjnr@gmail.com,chris@mqattach.com]";
this.eventCode = "DEFAULT";
this.metaData = metaData;
}
我的控制器
private EmailModel em;
@RequestMapping(value = "test", method = RequestMethod.Post)
public void post() throws Exception {
String uri= "TestUrl";
EmailModel em = new EmailModel();
EmailModel data =em;
HttpClient client = HttpClient.newBuilder().build();
HttpRequest request = HttpRequest.newBuilder()
.headers("Content-Type", "application/json")
.uri(URI.create(uri))
.POST(HttpRequest.BodyPublishers.ofString(String.valueOf(data)))
.build();
HttpResponse<?> response = client.send(request, HttpResponse.BodyHandlers.discarding());
System.out.println(em);
System.out.println(response.statusCode());
}