JAVA调用第三方接口

    科技2024-03-29  78

    //url为请求路径,params为参数map public static String sendPostRequest(String url, MultiValueMap<String, String> params){ RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); // 以表单的方式提交 headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); //将请求头部和参数合成一个请求 HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers); try { //忽略https证书请求 SslUtils.ignoreSsl(); } catch (Exception e) { e.printStackTrace(); } //执行HTTP请求 return restTemplate.postForEntity(url, request, String.class).getBody(); }

     

    Processed: 0.011, SQL: 8