我正在尝试使用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;