springboot 发送post请求
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public static String sendPOSTRequest(String url, MultiValueMap params) {
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpMethod method = HttpMethod.POST;
// 以表单的方式提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// 将请求头部和参数合成一个请求
HttpEntity> requestEntity = new HttpEntity<>(params, headers);
// 执行HTTP请求,将返回的结构使用String类格式化
ResponseEntity response = client.exchange(url, method, requestEntity, String.class);
return response.getBody();
}
String json = this.sendPOSTRequest(dataSyncConfig.getUrl(), null);