0

http请求的两种方式给出另一种结果,一种是JAVA代码,另一种是从网站复制元素。

我试图将它们匹配到相同的结果!当我使用 Java 代码时

    private static boolean isValid(URL url, HttpURLConnection connection) {

    BufferedReader reader;
    String line;
    StringBuffer responseContant = new StringBuffer();

    try {

        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setConnectTimeout(4000);
        connection.setReadTimeout(4000);

        int status = connection.getResponseCode();

        if (status > 299) {
            reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
            while ((line = reader.readLine()) != null)
                responseContant.append(line);
            reader.close();
        } else {
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            while ((line = reader.readLine()) != null)
                responseContant.append(line);
            reader.close();
            return true;
        }

    } catch (Exception e) {
        e.printStackTrace();

    }
    return false;
}

它给了我另一个值,而不是使用检查>复制>复制元素这怎么可能?以及如何解决这个问题?

多谢你们!!

4

0 回答 0