我没有找到解决问题的示例,因此想向你寻求帮助。我不能简单地使用JSON中的RestTemplate对象发送POST请求
每当我得到:
org.springframework.web.client.HttpClientErrorException:415不支持的媒体类型
我以这种方式使用RestTemplate:
... restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>(); list.add(new MappingJacksonHttpMessageConverter()); restTemplate.setMessageConverters(list); ... Payment payment= new Payment("Aa4bhs"); Payment res = restTemplate.postForObject("http://localhost:8080/aurest/rest/payment", payment, Payment.class);
我怎么了
这项技术对我有用:
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers); ResponseEntity<String> response = restTemplate.put(url, entity);
我希望这有帮助