用http协议请求使用代理ip

有这个一个需求,领导要求在网上给一个合做伙伴投票。投票系统作的不是很好有一些漏洞,做为程序猿的咱们,果断开始了自动刷票。
java

一、首先按F12查到网页源代码,截取出来投票连接。app

二、用程序模拟http get请求经过循环执行。dom

三、模拟执行的时候经过实践发现同一个ip在必定时间内只能投10次,故此须要用到代理ip网站

下面看程序:.net

public class Toupiao {
	public static void main(String args[])
	{
		new Thread(){
			public void run() {
				while(true){
					try{
						doGet();
						Random r = new Random();
						int d = r.nextInt(20);
						Thread.sleep(d*2000);
					}catch(Exception e){
						e.printStackTrace();
					}
				}
			};
		}.start();
	}
	
	public static void doGet(){

		 StringBuffer sb = new StringBuffer();
		 //建立HttpClient实例
		 HttpClient client = getHttpClient();
		 //建立httpGet
		 HttpGet httpGet = new HttpGet("http://rank.cn-healthcare.com/vote/judge/3/5678c9c370617c24df5ab8bd");
		 //执行
		 try {
		  HttpResponse response = client.execute(httpGet);
		  
		  HttpEntity entry = response.getEntity();
		  
		  if(entry != null)
		  {
		   InputStreamReader is = new InputStreamReader(entry.getContent());
		   BufferedReader br = new BufferedReader(is);
		   String str = null;
		   while((str = br.readLine()) != null)
		   {
		    sb.append(str.trim());
		   }
		   br.close();
		  }
		  
		 } catch (ClientProtocolException e) {
		  // TODO Auto-generated catch block
		  e.printStackTrace();
		 } catch (IOException e) {
		  // TODO Auto-generated catch block
		  e.printStackTrace();
		 }
		 System.out.println(sb.toString());
		
	}

	//设置代理

	public static HttpClient getHttpClient() {

	DefaultHttpClient httpClient = new DefaultHttpClient();
	 String proxyHost = "58.67.159.50"; //此处是代理ip
	 int proxyPort = 80; //代理端口
	 HttpHost proxy = new HttpHost(proxyHost,proxyPort);
	 httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
	 return httpClient;
	}
}

 还有一个问题就是找代理ip代理

http://www.youdaili.net/ code

此网站有许多代理ip,有些能够用有些不能够用须要本身去尝试。ip

你能够先在本身的电脑上设置下代理ip试试看能不能访问。以下:get

这样我如今本机的ip地址就是泰国的了,同时有些ip不能用则上网是上不了的。这样也能够判断代理ip的可用性。这里用代理ip也能够访问国外的网站可是速度和稳定性就。。。。。。。。it

本篇完

相关文章
相关标签/搜索