Reading data from a web page

I am trying to read data from a given webpage using Java.

public class WebpageReader {
    public static void main(String[] args) throws IOException {
        String line = null, response;
        URL url = new URL("http://www.google.co.in/");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn
                .getInputStream()));
        while (rd.readLine() != null) {
            line += rd.readLine();
        }
        System.out.println(line);

    }
}

code> But I get an exception rejection message. What could be the right way to get a date from a web page?

+3
source share
2 answers

Perhaps you are behind a proxy server that does not allow you to connect to a web resource using a Java application. You can configure the proxy server in java options. On Windows, you can do this from the control panel.

+1
source

You must have a proxy server or a firewall installed. This code works.

+1
source

All Articles