日期:2014-05-17 浏览次数:20678 次
-bash-3.2$ wget 'www.189.cn' --2012-05-07 09:17:32-- http://www.189.cn/ 正在解析主机 www.189.cn... 118.85.207.18 Connecting to www.189.cn|118.85.207.18|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:41881 (41K) [text/html] Saving to: `index.html.13' 100%[==========================================================================================>] 41,881 217K/s in 0.2s 2012-05-07 09:17:32 (217 KB/s) - `index.html.13' saved [41881/41881] -bash-3.2$ wget 'www.youku.com' --2012-05-07 09:19:26-- http://www.youku.com/ 正在解析主机 www.youku.com... 121.9.204.234 Connecting to www.youku.com|121.9.204.234|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:390160 (381K) [text/html] Saving to: `index.html.14' 100%[==========================================================================================>] 390,160 120K/s in 3.2s 2012-05-07 09:19:29 (120 KB/s) - `index.html.14' saved [390160/390160]
String ip = "1.1.1.1";//此处为dns解析出来的网站IP地址 Socket socket = new Socket(); socket.connect(new InetSocketAddress(ip, 80), 15000); boolean autoflush = true; PrintWriter out = new PrintWriter(socket.getOutputStream(), autoflush); BufferedReader in = new BufferedReader(new InputStreamReader(socket .getInputStream())); // send an HTTP request to the web server out.println("GET / HTTP/1.1"); out.println("Accept: */*"); out.println("User-Agent: cdut-boy"); out.println("Host: " + load_url);//此处为网站网址 out.println(); logger.info("获取HTTP页面首包时延发包结束,网站网址:load_url=" + load_url); boolean loop = true; while (loop) { if (in.ready())//此处 优酷 189 从来就读取不到首包,高手解答 { //..........do something...under... loop = false; } }