Spring RestTemplate post response

前端 未结 2 372
醉梦人生
醉梦人生 2020-12-30 01:25

I\'m not familiar with Spring RestTemplate.

But for this project I have to use Spring RestTemplate to send a POST call to consume a rest api.

I\'m using this

相关标签:
2条回答
  • 2020-12-30 02:17

    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();
    
    0 讨论(0)
  • 2020-12-30 02:20

    It will be pretty weird if RestTemplate couldn't get the response,as others have suggested. It is simply not true.

    You just use the postForEntity method which returns a

    http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/http/ResponseEntity.html

    And as the documentation suggests, the response entity has the status.

    0 讨论(0)
提交回复
热议问题