Spring RestTemplate发布响应 [英] Spring RestTemplate post response
本文介绍了Spring RestTemplate发布响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不熟悉Spring RestTemplate.
I'm not familiar with Spring RestTemplate.
但是对于这个项目,我必须使用Spring RestTemplate发送POST调用以使用rest api.
But for this project I have to use Spring RestTemplate to send a POST call to consume a rest api.
我正在使用以下代码:
String restCall = restTemplate.postForObject(url+restParm, null, String.class);
这很好.
我想获取HTTP状态代码(例如200 OK).我该怎么办? 谢谢.
I would like to retriveve the HTTP status code (E.g: 200 OK.). How could I do that ? Thanks.
推荐答案
您可以按以下方式使用postForEntity方法...
You use the postForEntity method as follows...
ResponseEntity<String> response = restTemplate.postForEntity(url+restParm, null, String.class);
HttpStatus status = response.getStatusCode();
String restCall = response.getBody();
这篇关于Spring RestTemplate发布响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文