no
DESKTOP-71BH0QO\L、ming
2021-04-22 ec78622b2952b22200ece6fedf9d02b3905941bb
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HttpClientUtil.java
@@ -13,7 +13,13 @@
import org.apache.http.util.EntityUtils;
import org.springframework.util.ObjectUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
@@ -86,5 +92,43 @@
    }
    /**
     * 使用http请求调用接口,参数类型为xml
     * @param urlStr    请求地址
     * @param data  请求参数
     * @return  调用结果
     */
    public static String httpsRequest(String urlStr,String data) {
        try {
            URL url = new URL(urlStr);
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
//            con.setRequestProperty("Pragma:", "no-cache");
            con.setRequestProperty("Cache-Control", "no-cache");
            con.setRequestProperty("Content-Type", "text/xml");
            OutputStreamWriter out = new OutputStreamWriter(con
                    .getOutputStream());
            log.info("urlStr=" + urlStr);
            log.info("xmlInfo=" + data);
            out.write(new String(data.getBytes("UTF-8")));
            out.flush();
            out.close();
            BufferedReader br = new BufferedReader(new InputStreamReader(con
                    .getInputStream()));
            String line = "";
            StringBuffer sb = new StringBuffer();
            for (line = br.readLine(); line != null; line = br.readLine()) {
                sb.append(line);
            }
            return sb.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}