获取URL地址的返回值

URL url = null;
        try {
            url = new URL("http://a.test.com/test.asp?action=get");
        } catch (MalformedURLException ex1) {
        }
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
        } catch (IOException ex2) {
            ex2.printStackTrace();
            return;
        }

        BufferedReader urlIn = null;
        try {
            urlIn = new BufferedReader(new InputStreamReader(connection.
                    getInputStream(), "gb2312"));
        } catch (IOException ex3) {
            ex3.printStackTrace();
            return;
        }
        String urlLine = "";
        StringBuffer line = new StringBuffer();
        try {

            while ((urlLine = urlIn.readLine()) != null) {
                line.append(urlLine.trim());
            }
        } catch (IOException ex4) {
            ex4.printStackTrace();
            return;
        }
        try {
            urlIn.close();
        } catch (IOException ex5) {
            ex5.printStackTrace();
            return;
        }
        urlLine = line.toString();

posted @ 2012-11-24 11:33  仓木_宇  阅读(571)  评论(0)    收藏  举报