本文整理匯總了Java中java.net.URLConnection.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java URLConnection.getContent方法的具體用法?Java URLConnection.getContent怎麽用?Java URLConnection.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.getContent方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: netCheck
import java.net.URLConnection; //導入方法依賴的package包/類
public static boolean netCheck(String[] testURLs) {
for (String testURL : testURLs) {
try {
URL url = new URL(testURL);
URLConnection conn = (URLConnection)url.openConnection();
conn.setConnectTimeout(TemplateConstants.CONN_SHORT_TIMEOUT);
conn.setReadTimeout(TemplateConstants.READ_SHORT_TIMEOUT);
conn.getContent();
return true;
} catch (Exception e) {
System.out.println("failed to connect to " + testURL);
}
}
return false;
}
示例2: announce
import java.net.URLConnection; //導入方法依賴的package包/類
private void announce(String trackerURL,byte[] hash,byte[] peerId,int port) {
try {
String strUrl = trackerURL
+ "?info_hash=" + URLEncoder.encode(new String(hash, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20")
+ "&peer_id=" + URLEncoder.encode(new String(peerId, Constants.BYTE_ENCODING), Constants.BYTE_ENCODING).replaceAll("\\+", "%20")
+ "&port=" + port
+ "&uploaded=0&downloaded=0&left=0&numwant=50&no_peer_id=1&compact=1";
//System.out.println(strUrl);
URL url = new URL(strUrl);
URLConnection con = url.openConnection();
con.connect();
con.getContent();
} catch(Exception e) {
e.printStackTrace();
}
}
示例3: canAccess
import java.net.URLConnection; //導入方法依賴的package包/類
private static boolean canAccess(String scheme, InetSocketAddress addr) {
if (addr == null)
return false;
try {
URL url = new URL(scheme + "://" + NetUtils.getHostPortString(addr));
URLConnection conn = connectionFactory.openConnection(url);
conn.connect();
conn.getContent();
} catch (Exception e) {
return false;
}
return true;
}