【发布时间】:2020-03-04 10:27:52
【问题描述】:
我想做一个postForEntity,但结果始终为空。可能是什么原因?
@Override
public ResponseEntity<Void> updateContactProperty(final Long contactId, final String json) throws RestClientException {
ResponseEntity<Void> crmResponse = null;
try {
crmResponse = crmRestTemplate.postForEntity(
"https://api.hubapi.com/contacts/v1/contact/vid/400000001/profile?hapikey=myApiKey", json, Void.class);
} catch (HttpClientErrorException e) {
e.printStackTrace();
} catch (HttpStatusCodeException e) {
e.printStackTrace();
}catch (RestClientException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} catch (Error r) {
r.printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
}
return crmResponse;
}
我试过ResponseEntity<Void>、ResponseEntity<Object>、ResponseEntity<String>。
向 RestTemplate 注册的 MessageConverters:
- ByteArrayHttpMessageConverter
- StringHttpMessageConverter
- ResourceHttpMessageConverter
- SourceHttpMessageConverter
- AllEncompassingFormHttpMessageConverter
- Jaxb2RootElementHttpMessageConverter
- MappingJackson2HttpMessageConverter
不能捕获任何异常...调用只是进行,但没有任何反应。
【问题讨论】:
-
不,好像不一样。
-
Object.class而不是Void.class -
正如您在我的问题中看到的那样,我已经尝试使用 ResponseEntity
、ResponseEntity
标签: spring-boot null resttemplate