Robin clave
Robin clave

Reputation: 638

Read data from webpage

I am trying to read data from the given web page 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);

    }
}

But I'm getting the connection refused exception. What might be correct way to get the date from webpage?

Upvotes: 3

Views: 12843

Answers (2)

kgiannakakis
kgiannakakis

Reputation: 104178

You are probably behind a proxy that doesn't allow you to connect to a web resource through a java application. You can configure a proxy in the java options. In Windows you can do that from the Control Panel.

Upvotes: 1

Nishant
Nishant

Reputation: 55866

You must be having proxy or firewall set. This code works.

Upvotes: 1

Related Questions