2013-09-05 82 views
0

返回的HTML我有這樣的代碼:獲取從URL請求

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並將其打印在屏幕上? 這不起作用。

感謝,

+0

好的網址爲例:d – realsim

+0

:d,我知道我錯過了:)) –

回答