我正在使用spring在robospice。我需要将标题与get请求放在一起,所以我使用了exchange()方法。该代码没有错误,但没有获取任何内容。
public MList loadDataFromNetwork() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add(key,keyValue);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<MList> response=getRestTemplate().exchange(url,HttpMethod.GET,entity,MList.class);
return getRestTemplate().exchange(url, HttpMethod.GET,new HttpEntity<Object> (headers),MList.class).getBody();
}发布于 2014-11-14 10:20:11
RestTemplate restTemplate=new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
HttpHeaders headers = new HttpHeaders();
headers.add(key,keyValue);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<Pojo> response=restTemplate.exchange(url,HttpMethod.GET,entity,Pojo.class);
return response.getBody();当我像这样编辑代码的时候它就起作用了。
但是我在使用时得到了一个空指针异常。
RestTemplate restTemplate=getRestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter())https://stackoverflow.com/questions/26667895
复制相似问题