2015-10-28 25 views
0

我試圖從響應頭部獲取一些認證值並獲取填充對象。但我的問題是,我得到的是標題值或填充對象,如示例中所示。從RestTemplate獲取標題數據和對象

RestTemplate restTemplate = new RestTemplate(); 
String requestJson = "{ \"identifier\": \"username\", \"password\": \"pw\" } "; 

HttpHeaders headers = new HttpHeaders(); 
headers.setContentType(MediaType.APPLICATION_JSON); 
headers.add("KEY","apikey"); 
HttpEntity<String> entity = new HttpEntity<String>(requestJson,headers); 

Login login = restTemplate.postForObject("https://url.com",entity, Login.class); 

HttpEntity<String> response = template.exchange("https://url.com", HttpMethod.POST, entit, Login.class); 

String resultString = response.getBody(); 
HttpHeaders headers = response.getHeaders(); 

有沒有辦法做到的響應=>對象交換以後呢? 或者完全不同的方式來解決這個問題?

回答

0

我解決了使用此代碼我的問題:

ResponseEntity<Login> response = restTemplate.exchange(url, HttpMethod.POST, request, Login.class); 
Login login = response.getBody(); 
HttpHeaders headers = response.getHeaders(); 

所以我的結果是填充登錄對象的登錄名和我的頭是在頭部。