package com.homlin.module.qyapi.utils;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.commons.httpclient.methods.PostMethod;import org.apache.commons.httpclient.methods.RequestEntity;import org.apache.commons.httpclient.methods.StringRequestEntity;import org.apache.commons.httpclient.params.HttpMethodParams;import java.io.IOException;/** * super_dev_007 2020/11/22 */public class MyHttpClientThird {    /**     * 发动POST申请     *     * @param url       url     * @param paramJson 参数的json格局     */    public static String sendPost(String url, String paramJson) {        // 创立httpClient实例对象        HttpClient httpClient = new HttpClient();        // 设置httpClient连贯主机服务器超时工夫:15000毫秒        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(15000);        // 创立post申请办法实例对象        PostMethod postMethod = new PostMethod(url);        // 设置post申请超时工夫        postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000);        postMethod.addRequestHeader("Content-Type", "application/json");        try {            //json格局的参数解析            RequestEntity entity = new StringRequestEntity(paramJson, "application/json", "UTF-8");            postMethod.setRequestEntity(entity);            httpClient.executeMethod(postMethod);            String result = postMethod.getResponseBodyAsString();            postMethod.releaseConnection();            return result;        } catch (IOException e) {            e.printStackTrace();        }        return null;    }    /**     * 发动GET申请     *     * @param urlParam url申请,蕴含参数     */    public static String sendGet(String urlParam) {        // 创立httpClient实例对象        HttpClient httpClient = new HttpClient();        // 设置httpClient连贯主机服务器超时工夫:15000毫秒        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(15000);        // 创立GET申请办法实例对象        GetMethod getMethod = new GetMethod(urlParam);        // 设置post申请超时工夫        getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000);        getMethod.addRequestHeader("Content-Type", "application/json;charset=UTF-8");        try {            httpClient.executeMethod(getMethod);            String result = getMethod.getResponseBodyAsString();            getMethod.releaseConnection();            return result;        } catch (IOException e) {            e.printStackTrace();        }        return null;    }}