Spring RestTemplate发布响应

编程入门 行业动态 更新时间:2024-10-26 10:37:11
本文介绍了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发布响应

本文发布于:2023-10-11 13:47:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   RestTemplate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!