休息模板给出400错误请求错误

时间:2017-10-18 13:33:54

标签: spring resttemplate

我正在尝试使用Springs RestTemplate进行REST调用,但我一直收到HTTP响应状态400(错误请求)。

有人可以帮忙吗?

RestTemplate transactiontemplate = new RestTemplate();

HttpHeaders transactionheaders = new HttpHeaders();
transactionheaders.add("Authorization", "Bearer "+AccessToken);
transactionheaders.add("Accept", "application/json");
transactionheaders.add("Accept-Encoding", "application/gzip");
transactionheaders.add("Content-Type", "application/json");

ObjectMapper mapper = new ObjectMapper();

//System.out.println(mapper.writeValueAsString(transaction));
HttpEntity<TransactionRequestDTO> transactionEntity = new                 
HttpEntity<TransactionRequestDTO> (transaction, transactionheaders);
ResponseEntity<String> transactionresponse = transactiontemplate.exchange(LocationUrl+"/"+locationId+"/transactions", 

HttpMethod.POST, transactionEntity, String.class);
//String answer = transactiontemplate.postForObject(LocationUrl+"/"+locationId+"/transactions", transactionEntity, String.class);

//System.out.println(answer);
ObjectMapper transactionmapper = new ObjectMapper();
TransactionResponseDTO transactionResponseObject = transactionmapper.readValue(transactionresponse.getBody(), TransactionResponseDTO.class);
return transactionResponseObject;

0 个答案:

没有答案