1
zj
2026-02-09 ad1097015ebbd712f86761ee85e035c0b2bf5ab4
src/main/java/com/nq/utils/http/HttpRequest.java
@@ -68,48 +68,40 @@
    /*
    *抓數據專用,
    *signature:授權碼
    * timestamp:時間戳
    * url
    */
    public static String doGrabGet(String url) throws Exception {
        // Request URL: http://gateway.jinyi999.cn/rjhy-news/api/1/tcy/news/hotlist?columnCodes=cjyw&appCode=tcy&showPermission=0&limit=20&hasContent=0&pageNo=1
        URL localURL = new URL(url);
        URLConnection connection = localURL.openConnection();
        HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
        httpURLConnection.setRequestProperty("Accept-Charset", "utf-8");
        InputStream inputStream = null;
        InputStreamReader inputStreamReader = null;
        BufferedReader reader = null;
        httpURLConnection.setConnectTimeout(12000); // 设置连接超时时间
        httpURLConnection.setReadTimeout(12000); // 设置读取超时时间
        StringBuffer resultBuffer = new StringBuffer();
        String tempLine = null;
        if (httpURLConnection.getResponseCode() >= 300) {
            throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
        }
        try {
            inputStream = httpURLConnection.getInputStream();
            inputStreamReader = new InputStreamReader(inputStream);
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
        try (InputStream inputStream = httpURLConnection.getInputStream();
             InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
             BufferedReader reader = new BufferedReader(inputStreamReader)) {
            String tempLine;
            while ((tempLine = reader.readLine()) != null) {
                resultBuffer.append(tempLine);
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
            httpURLConnection.disconnect(); // 断开连接,释放资源
        }
        return resultBuffer.toString();
    }
    public static String doPost(String url, Map<String, String> params) throws Exception {
        HttpPost httpPost = new HttpPost(url);