httpclient

package vote;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class Vote {

	public static void main(String args[]) throws ClientProtocolException, IOException
	{
	//	HttpClient httpclient = new DefaultHttpClient();
		
		String url="";
		
		for(int j=180;j<230;j++)
		{
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httpost = new HttpPost(url); 
		
		
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();  
	    nvps.add(new BasicNameValuePair("username", "dsdgdd01"+j));  
	    nvps.add(new BasicNameValuePair("email", "gfdg0101"+j+"@cm4d.cn"));  
	    nvps.add(new BasicNameValuePair("password", "101010")); 
	    nvps.add(new BasicNameValuePair("password2", "101010"));
	    HttpEntity httpentity = new UrlEncodedFormEntity(nvps, "utf-8");
	    httpost.setEntity(httpentity);
	    
	    //伪造ip
	    httpost.setHeader("X-FORWARDED-FOR ", "213.125.18."+j);
	   // httpost.addHeader("X-FORWARDED-FOR ", "213.125.33.56");
	    HttpResponse response = httpclient.execute(httpost);
	    System.out.println(response.getEntity());
	    
	    //获得cookie
	    Header locationHeader = response.getFirstHeader("Set-Cookie");  
	   System.out.println(locationHeader);
	    Header h[]=response.getAllHeaders();
	    for(int i=0;i<h.length;i++)
	    {
	    	System.out.println(h[i].getName()+": "+h[i].getValue());
	    }
	    
	    //断开连接
	    httpost.abort();
	   
	 //   httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.ACCEPT_ALL);
	 
	    String url2="";
	    HttpPost post2=new HttpPost(url2);
	    List<NameValuePair> pram2=new ArrayList<NameValuePair>();
	    pram2.add(new BasicNameValuePair("vid", "20"));
	    HttpEntity httpentity2 = new UrlEncodedFormEntity(pram2, "utf-8");
	    post2.setEntity(httpentity2);
	    post2.setHeader("Cookie", locationHeader.toString());
	    HttpResponse response2 = httpclient.execute(post2);
	    System.out.println(response2.getEntity());
	    post2.abort();
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值