я весна-андроида, чтобы подключиться к серверу, чтобы получить JSON и сопоставить его с классом объекта:весна RestTemplate нет Content-Type
баночках:
jackson-core-asl-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
spring-android-auth-1.0.0.M4.jar
spring-android-core-1.0.0.M4.jar
spring-android-rest-template-1.0.0.M4.jar
Источник:
RestTemplate restTemplate = new RestTemplate(/* clientHttpRequestFactory */);
ClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
restTemplate.setRequestFactory(clientHttpRequestFactory);
MappingJacksonHttpMessageConverter httpMessageConverter = new MappingJacksonHttpMessageConverter();
List<MediaType> supportedMediaTypes = new ArrayList<MediaType>();
supportedMediaTypes.add(new MediaType("application", "json"));
httpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
List<HttpMessageConverter<?>> httpMessageConverters = restTemplate
.getMessageConverters();
httpMessageConverters.add(httpMessageConverter);
restTemplate.setMessageConverters(httpMessageConverters);
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("param1", "param1");
map.add("param2", "2");
T t = restTemplate.postForObject(url, map, T.class);
результат от сервера является строка JSON, как:
{"aaa":"111", "bbb":"222"}
Результат:
Caused by: org.springframework.web.client.RestClientException: Cannot extract response: no Content-Type found
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:60)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:470)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:425)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:303)
Там не должно быть в заголовках ответа нет Content-Type
. Как я могу сделать RestTemplate
не заботятся о Content-Type
?
Проблема не связана с отсутствием содержимого 204. Он говорит, что сервер возвращает тело ответа, но без заголовка «Content-Type». –