简单的问题:
是否可以同时请求多个 httpURLConnection?我正在创建一个工具来检查某些服务器上是否存在页面,目前,Java 似乎要等到每个 httpURLConnection 完成才能启动一个新的。这是我的代码:
public static String GetSource(String url){
String results = "";
try{
URL SourceCode = new URL(url);
URLConnection connect = SourceCode.openConnection();
connect.setRequestProperty("Host", "www.someserver.com");
connect.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0");
connect.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
connect.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
connect.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
connect.setRequestProperty("Keep-Alive", "115");
connect.setRequestProperty("Connection", "keep-alive");
BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream(), "UTF-8"));
String inputLine;
while ((inputLine = in.readLine()) != null){
results += inputLine;
}
return results;
}catch(Exception e){
// Something's wrong
}
return results;
}
非常感谢!