Posted on 2008-04-05 13:04 
leekiang 阅读(293) 
评论(0)  编辑  收藏  所属分类: 
ruby 
			 
			
		 
		
		
				
				require 
				'
				net/http
				'
				
						
						
count 
				=
				 
				1
				..
				100000
				  
				#
				 define an array
				
						
				
				
						
count.each{      
				#
				 each 
				
						
				
				|
				index
				|
				             
				#
				 element is index  1 2 3 4 5 6
				
						
				
				printf 
				"
				#{index} 
				"
				 
				#
				print index and space
				
						
				
				h 
				=
				 Net::HTTP.new(
				'
				space.cnblogs.com
				'
				,
				80
				) 
				#
				 create a object
				
						
				
				resp, data 
				=
				 h.get(
				'
				/group/topic/1605/
				'
				,nil) 
				#
				 get 
				
						
				
				if
				 resp.code 
				!=
				 
				"
				200
				"
				 
				#
				 if http response status code not is 200 
				
						
				
				  puts resp.code    
				#
				put status code
				
						
				
				  puts resp.message 
				#
				put status message
				
						
				
				  
  resp.each{    
				#
				put headers
				
						
				
				  
				|
				key, val
				|
				
						
  puts 
				"
				#{key}\t\t\t#{val}
				"
				
						
  }
  
  p data    
				#
				put html
				
						
				
				  
				break
				 
				#
				 break the eache
				
						
				
				end
				#
				sleep(1) #sleep  use second do inteval
				
						
				
				}
		
		来源:http://www.cnblogs.com/coderlee/archive/2008/03/25/1121652.html