我不熟悉 Spring RestTemplate。
但是对于这个项目,我必须使用 Spring RestTemplate 发送一个 POST 调用来使用一个 rest api。
我正在使用此代码:
String restCall = restTemplate.postForObject(url+restParm, null, String.class);
这工作正常。
我想检索 HTTP 状态代码(例如:200 OK。)。我怎么能那样做? 谢谢。
最佳答案
你使用 postForEntity 方法如下...
ResponseEntity<String> response = restTemplate.postForEntity(url+restParm, null, String.class);
HttpStatus status = response.getStatusCode();
String restCall = response.getBody();
关于java - Spring RestTemplate 发布响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16401909/