0

Two ways to http request give another results one by JAVA code and second by copy element from website.

I am try to match them to same result! When I use Java Code

    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;
}

It give me another value instead use inspect> copy> copy element How it possible? and how to fix this issue?

Thanks guys!!

Lichay Tiram
  • 283
  • 3
  • 12
  • What do you mean with: "Two ways to http request"? If status code is bigger than 299 you are reading from the Error Stream, otherwise, you read from the Output Stream. – sgtcortez Nov 30 '20 at 14:27
  • no my status is 200 but i get another values if using " inspect> copy> copy element" or java request – Lichay Tiram Nov 30 '20 at 16:12
  • I have not understood your question yet. And, if there is no answer yet, and this question is not close, may be that others did not understand too. Try to clarify it, and provide some outputs. – sgtcortez Nov 30 '20 at 19:42
  • the output very long more then 4000lins, just try yourself. you shuld go https://www.google.co.il and then right click > inspect > copy all html code . after compare it to java http request value and see they isn't the same – Lichay Tiram Dec 01 '20 at 18:21

0 Answers0