Read data from webpage

时间秒杀一切 提交于 2019-12-12 12:33:24

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5232535/read-data-from-webpage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!