0

我有这个代码:

try {
        URL url = new URL("http://www.gooel.com");

        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
        httpCon.setDoOutput(true);
        //httpCon.setRequestMethod("GET");
        OutputStreamWriter out = new OutputStreamWriter(
            httpCon.getOutputStream());
        out.write("Resource content");
        out.close();
        // httpCon.getInputStream();

        BufferedReader in = new BufferedReader(new InputStreamReader(
      httpCon.getInputStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);
        in.close();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

如何从此连接中获取返回的 html 并将其打印在屏幕上?这行不通。

谢谢,

4

1 回答 1

0

最简单的答案: google HttpURLConnection

使用第一击: Java:简单的 HTTPUrlConnection 示例

你完成了!

于 2013-09-05T11:58:26.227 回答