2012-03-12 53 views
3

我只想为网址获取页面标题而不下载页面内容。这是我使用的是什么现在:Java:获取页面标题,然后关闭连接

... 
URL targetUrl = new URL(urlValue); 
HttpURLConnection conn = (HttpURLConnection) targetUrl.openConnection(); 
String value = conn.getHeaderField(0); 
... 

我不知道这是获得头,然后退出或它做什么。

回答

7

发送HEAD请求而不是GET请求(这是默认方法)。

conn.setRequestMethod("HEAD"); 
// ... 

否则返回完整响应正文。