本文介绍了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发布响应
发布评论