// Set the Accept header
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(new MediaType("application","vnd.livescore_app.api.v1+json")));
requestHeaders.setContentType(new MediaType("application","json;charset=utf-8"));
HttpEntity> requestEntity = new HttpEntity(requestHeaders);
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson message converter
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
// Make the HTTP GET request, marshaling the response from JSON to an array of Events
ResponseEntity responseEntity = restTemplate.exchange("https://example.com", HttpMethod.GET, requestEntity, AppVersionObject.class);
AppVersionObject object = responseEntity.getBody();
崩溃,并显示以下日志跟踪
05-13 10:55:42.656: E/AndroidRuntime(19401): FATAL EXCEPTION: Thread-1470
05-13 10:55:42.656: E/AndroidRuntime(19401): java.lang.IllegalArgumentException:Invalid token character ';' in token "json;charset=utf-8"
05-13 10:55:42.656: E/AndroidRuntime(19401): at org.springframework.http.MediaType.checkToken(MediaType.java:377)
05-13 10:55:42.656: E/AndroidRuntime(19401): at org.springframework.http.MediaType.(MediaType.java:351)
05-13 10:55:42.656: E/AndroidRuntime(19401): at org.springframework.http.MediaType.(MediaType.java:303)
05-13 10:55:42.656: E/AndroidRuntime(19401): at com.madinsweden.livescoretennis.service.CheckAppVersionTask.run(CheckAppVersionTask.java:41)
05-13 10:55:42.656: E/AndroidRuntime(19401): at java.lang.Thread.run(Thread.java:856)
我当然可以改变的内容类型更加规范application/json但后来我碰到下面的错误。
05-13 11:03:07.054: E/AndroidRuntime(20010): org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.madinsweden.livescoretennis.backend.AppVersionObject] and content type [application/vnd.livescore_app.api.v1+json;charset=utf-8]
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:79)
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:655)
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(Rest Template.java:641)
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
05-13 11:03:07.054: E/AndroidRuntime(20010): at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)
05-13 11:03:07.054: E/AndroidRuntime(20010): at com.madinsweden.livescoretennis.service.CheckAppVersionTask.run(CheckAppVersionTask.java:51)
05-13 11:03:07.054: E/AndroidRuntime(20010): at java.lang.Thread.run(Thread.java:856)
2013-05-13
mach