public class Main {
public static void main(String arg[])
{
HttpURLConnection conn = null;
String url="http://www.baidu.com/";
System.out.println("url="+url);
try {
System.out.println("url="+url);
Properties prop=System.getProperties();
prop.put("http.proxyHost","133.64.81.235");
prop.put("http.proxyPort","8080");
System.setProperties(prop);
System.out.println("url="+url);
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(1000);
conn.connect();
String result = conn.getResponseMessage();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line ;
//String result ="";
while( (line =br.readLine()) != null ){
result += "\n"+line;
}
System.out.println(result);
}catch (Exception e)
{
}finally {
conn.disconnect();
}
}
}
简单的获取页面源文件的例子
最新推荐文章于 2020-07-30 11:25:49 发布