springboot 发送post请求
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public static String sendPOSTRequest(String url, MultiValueMap<String, String> params) {
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpMethod method = HttpMethod.POST;
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
return response.getBody();
}
String json = this.sendPOSTRequest(dataSyncConfig.getUrl(), null);