jiazx0107@163.com
2023-11-18 328eba66ddc6fdf2f324b9cd04cd6acec9f642de
src/main/java/com/fzzy/gateway/util/GatewayHttpUtil.java
@@ -9,12 +9,8 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Set;
/**
 * 网关专用HTTP请求工具类
@@ -24,12 +20,13 @@
    /**
     * 执行GET请求
     *
     * @param url
     * @param paramsMap
     * @return
     * @throws Exception
     */
    public static String doGet(String url,Map<String, String> paramsMap) throws Exception{
    public static String doGet(String url, Map<String, String> paramsMap) throws Exception {
        CloseableHttpClient client = HttpClients.createDefault();
        String responseText = "";
        CloseableHttpResponse response = null;
@@ -37,7 +34,7 @@
            String getUrl = url + "?";
            if (paramsMap != null) {
                for (Map.Entry<String, String> param : paramsMap.entrySet()) {
                  //  getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&";
                    //  getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&";
                    getUrl += param.getKey() + "=" + URLEncoder.encode(param.getValue(), "UTF-8") + "&";
                }
            }
@@ -51,18 +48,17 @@
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                responseText = EntityUtils.toString(entity,"UTF-8");
                responseText = EntityUtils.toString(entity, "UTF-8");
            }
        } catch (Exception e) {
            log.error("http request failed", e);
            log.error("http request failed--{}", e.getMessage());
        } finally {
            try {
                response.close();
                if (null != response) response.close();
            } catch (Exception e) {
                log.error("", e);
            }
        }
        return responseText;
    }