Я все еще новичок в Java и Springboot, и каждый раз, когда я обращаюсь к отправке запросов API, я застреваю.
Вот пример ответа API, который я пытаюсь проанализировать -
{
"respCode": "0",
"statusCode": "0"
}
Ниже приведен код -
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
body.add("merchantTxnId", enqr.getMerchantTxnId());
body.add("pgTxnId", enqr.getPgTxnId());
RestTemplate restTemplate = RestTemplateClient.getRestTemplate(30, 30);
String signature = "some signature";
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type","application/json");
headers.set("access_key", accessKey);
headers.set("signature", signature);
headers.set("Accept", "application/json");
HttpEntity<MultiValueMap<String, String>> entity = new
HttpEntity<MultiValueMap<String, String>>(
body, headers);
String url = UriBuilder.fromPath(baseUrl).path("/refund")
.toString();
try {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> ent = restTemplate.exchange(url,
HttpMethod.POST, entity, Map.class);
if (!ent.getBody().get("statusCode").equals("0"))
throw new Exception((String) ent.getBody().get("respMsg"));
} catch (Exception ex) {
logger.info("CouldNot Refund to Source due to {}", ex.getMessage());
return false;
}
Я получаю исключение при вызове exchange()
-
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [application/octet-stream]