本文整理汇总了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;
}