I have a problem, Connect call Post method encountered 415 Unsupported Media Type: [no body], how to solve?? Is there something wrong with my writing? I need answers fast. thank you.
@Autowired
private final AtlassianHostRestClients atlassianHostRestClients;
public TestController(AtlassianHostRestClients atlassianHostRestClients) {
this.atlassianHostRestClients = atlassianHostRestClients;
}
@GetMapping("/test")
public String helloWorld() {
return "test";
}
@RequestMapping(value = "/covertPage", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ContextJwt
@ResponseBody
public Result<String> covertPage(@AuthenticationPrincipal AtlassianHostUser hostUser) throws JsonProcessingException {
String html;
String content = atlassianHostRestClients.authenticatedAs(hostUser).getForObject("/rest/api/content/" + 16973836 + "?expand=body.view", String.class);
JSONObject jsonObject = JSONObject.parseObject(content);
if (Objects.nonNull(jsonObject)) {
if (Objects.nonNull(jsonObject.getJSONObject("body"))) {
html = jsonObject.getJSONObject("body").getJSONObject("view").get("value").toString();
JsonNodeFactory jnf = JsonNodeFactory.instance;
ObjectNode payload = jnf.objectNode();
payload.put("value", html);
payload.put("representation", "view");
ObjectMapper mapper = new ObjectMapper();
String a = mapper.writeValueAsString(payload);
ResponseEntity responseEntity = atlassianHostRestClients.authenticatedAs(hostUser).postForObject("/rest/api/contentbody/convert/export_view", payload.toString(), ResponseEntity.class);
if(Objects.nonNull(responseEntity)){
return Result.success(responseEntity.getStatusCode().toString());
}
}
}
return Result.success("success");
}
The screenshot of the problem is as follows: