sinake
15 小时以前 02e4e3a9fcfbe2a366fc75868dfa019145cea9d2
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
@@ -13,6 +13,12 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants;
@@ -112,6 +118,7 @@
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setRequestProperty("Accept-Charset", "utf-8");
            conn.setRequestProperty("Charsert", "UTF-8");
            conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
            conn.setDoOutput(true);
            conn.setDoInput(true);
@@ -168,7 +175,7 @@
                }
            }
            out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8));
            log.error("---------param发送的数据为:{}",param);
            log.info("---------param发送的数据为:{}",param);
            out.print(param);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
@@ -220,7 +227,7 @@
                }
            }
            log.error("发送参数:{}", param);
            log.info("发送参数:{}", param);
            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = param.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
@@ -308,4 +315,21 @@
            return true;
        }
    }
    public static String sendPost(String url){
        HttpPost post = new HttpPost(url);
        CloseableHttpClient client = HttpClients.createDefault();
        //启动执行请求,并获得返回值
        CloseableHttpResponse execute = null;
        try {
            execute = client.execute(post);
            HttpEntity entity = execute.getEntity();
            //把实体对象转换为string
            return EntityUtils.toString(entity, "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "调用失败";
    }
}