Я использую сторонний API для каких-то целей.
Этот API-интерфейс отвечает URL-адресом, который в основном является URL-адресом Amazon AWS, который фактически содержит данные, которые меня интересуют.
Я могу вызвать URL-адрес AWS через браузер и почтальон, который отвечает данными.
Но через код я получаю следующую ошибку:
InvalidMimeTypeException: Invalid mime type "json": does not contain '/'
Я использую Spring Boot ичтобы сделать http calss, я использую RestTemplate
.
Заголовок ответа:
accept-ranges →bytes
content-length →1428
content-type →json
date →Thu, 25 Oct 2018 10:05:57 GMT
last-modified →Wed, 24 Oct 2018 18:44:44 GMT
server →AmazonS3
Тип содержимого "json"
Код, который я использовал:
protected HttpHeaders httpHeader(String encodedApiKey) {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", " */*");
headers.add(HttpHeaders.ACCEPT, " */*");
headers.add(HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.name());
if (encodedApiKey != null && !encodedApiKey.isEmpty()) {
headers.add("Authorization", "Basic " + encodedApiKey);
}
return headers;
}
private HttpEntity<Tickets> getHttpEntity(String apiKey) {
if (apiKey== null || apiKey.isEmpty()) {
return new HttpEntity<>(httpHeader(null));
}
return new HttpEntity<>(httpHeader(encodeBase64(apiKey)));
}
ResponseEntity<Tickets> responseEntity = restTemplate.exchange(awsUri,
HttpMethod.GET,
httpEntity, new ParameterizedTypeReference<Tickets>() {});
}
Это исключение:
org.springframework.http.InvalidMediaTypeException: Invalid mime type "json": does not contain '/'
at org.springframework.http.MediaType.parseMediaType(MediaType.java:534)
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:869)
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:124)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:88)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:959)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:942)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:689)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:662)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:339)
- Что я делаю не так?
- Я пытался использовать
ClientHttpRequestInterceptor
, но это не изменит заголовок ответа сервера (или Content-Type на application / json )
У кого-нибудь есть идеи?