rentaiming
2024-07-16 2eb4e3b8ca10cc860fe0681f9737803cfb145e25
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/utli/HttpUtils.java
@@ -1,22 +1,23 @@
package com.ruoyi.goods.utli;
import com.ruoyi.common.core.utils.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.*;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -180,6 +181,29 @@
        return httpClient.execute(request);
    }
    public static String httpPost(String url, String json) throws Exception {
        //初始HttpClient
        CloseableHttpClient httpClient = HttpClients.createDefault();
        //创建Post对象
        HttpPost httpPost = new HttpPost(url);
        //设置Content-Type
        /* httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");*/
        StringEntity se = new StringEntity(json,"UTF-8");
        se.setContentType("application/x-www-form-urlencoded");
        httpPost.setEntity(se);
        //发起请求,获取response对象
        CloseableHttpResponse response = httpClient.execute(httpPost);
        //获取请求码
        //response.getStatusLine().getStatusCode();
        //获取返回数据实体对象
        HttpEntity entity = response.getEntity();
        //转为字符串
        String result = EntityUtils.toString(entity, "UTF-8");
        return result;
    }
    /**
     * Put String
     * @param host