我正在使用圖形 api:
GET /users/{id | userPrincipalName}/photo/$value
使用我的訪問令牌獲取特定用戶的個人資料照片。在郵遞員中,我可以使用上面的 get 呼叫看到影像。在我的 spring-boot 應用程式中,我使用如下:
final ResponseEntity<Object> profilePicture = restTemplate.exchange(graphUrl, HttpMethod.GET, new HttpEntity<>((header)), new ParameterizedTypeReference<>() {});
我收到以下錯誤:
Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [image/jpeg]
我已將 RestTemplate 定義為:
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
有人可以幫我嗎?
uj5u.com熱心網友回復:
您需要為MessageConverter您的RestTemplate.
就像是:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
ResponseEntity<byte[]> response = restTemplate.exchange(graphUrl,
HttpMethod.GET, new HttpEntity<>((header)), byte[].class);
您可以在此處閱讀有關此主題的更多資訊:https ://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/HttpMessageConverter.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/510516.html
