Spring Boot 4 HTTPクライアント
RestTemplate
getForObject
レスポンスのBodyをString型で取得
String s = new RestTemplate()
.getForObject("http://officeyone.s324.xrea.com/officeyone.shop", String.class);
getForEntity
レスポンスのBodyをString型で取得
ResponseEntity<String> entity = new RestTemplate()
.getForEntity("http://officeyone.s324.xrea.com/officeyone.shop", String.class);
HttpStatus status = entity.getStatusCode();
HttpHeaders header = entity.getHeaders();
String s = entity.getBody();
postForEntity
ResponseEntity<String> res = new RestTemplate()
.postForEntity("http://officeyone.s324.xrea.com/officeyone.shop", "aaa", String.class);
String s = res.getBody();
RestOperations
RestOperations restoperations = new RestTemplateBuilder()
接続タイムアウト設定
.setConnectTimeout(30000)
応答タイムアウト設定
.setReadTimeout(60000)
基本認証設定
.basicAuthorization("user", "pass")
作成
.build();
String s = restoperations.getForObject("http://officeyone.s324.xrea.com/officeyone.shop", String.class);