我正在尝试点击POST API,该API返回的令牌格式为“ ABC:XYZ”。当我尝试将此解析为字符串时,它无法执行此操作。我怀疑,这是因为令牌中存在冒号(:),因此将其视为JSON。我正在使用REST模板。我尝试将“接受标头”设置为MediaType.TEXT_PLAIN,但这对我也不起作用。
下面是我的代码
ResponseEntity<Object> response = null;
HttpHeaders headers = new HttpHeaders();
try {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl("https://XXXX/YYYY");
Map<String, String> criteria = new HashMap<>();
criteria.put("username", "JOHNDOE");
uriBuilder.queryParam("username", "{username}");
criteria.put("target_site", "SITE");
uriBuilder.queryParam("target_site", "{target_site}");
headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
HttpEntity<String> entity = new HttpEntity<>(headers);
// ParameterizedTypeReference<String> responseType = new ParameterizedTypeReference<String>() {
// };
response =
restTemplateSSLIgnore.exchange(
uriBuilder.build().toUriString(),
HttpMethod.POST,
entity,
Object.class,
criteria);
logger.info(response.getBody());
}catch (Exception e){
logger.error(e.getMessage(),e);
return false;
}
return response.getBody();
有人可以帮我吗?