httpclient怎么不能成功注册百度或是各论坛

得瑟来的 发布于 2011/10/26 12:27
阅读 673
收藏 0

不能注册成功

 

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

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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;
import org.apache.http.util.EntityUtils;

public class SimpleHttpPut { 
	public static void main(String[] args) {
		
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost("https://passport.baidu.com/?reg");
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
			nameValuePairs.add(new BasicNameValuePair("acc","wia11kai"));
			nameValuePairs.add(new BasicNameValuePair("pas","aa11bb22cc"));
			nameValuePairs.add(new BasicNameValuePair("u_pas1","aa11bb22cc"));
			nameValuePairs.add(new BasicNameValuePair("sex","1"));
			nameValuePairs.add(new BasicNameValuePair("mail","123abc456@kwi.com"));
			nameValuePairs.add(new BasicNameValuePair("verifycode","此处为打开百度注册页面后显示的验证码手动填写的"));
			post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			HttpResponse response = client.execute(post);
			HttpEntity entity = response.getEntity();
			System.out.println(response.getStatusLine());
			if(entity != null){
				System.out.println("Response content length:" +entity.getContentLength());
				String content = EntityUtils.toString(entity);
				System.out.println("Resonse content:"+content);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			client.getConnectionManager().shutdown();
		}
	}
}

加载中
0
ddatsh
ddatsh

你是先在浏览器打开注册页面得到一个验证码

再把这个验证码放到代码里来用?

 

0
得瑟来的
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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;
import org.apache.http.util.EntityUtils;

public class SimpleHttpPut { 
	public static void main(String[] args) {
		
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://www.jueaivip.com/register.php?regsubmit=yes");
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
			nameValuePairs.add(new BasicNameValuePair("username","wia11kai"));
			nameValuePairs.add(new BasicNameValuePair("password","aa11bb22cc"));
			nameValuePairs.add(new BasicNameValuePair("password2","aa11bb22cc"));
			nameValuePairs.add(new BasicNameValuePair("email","123abc456@kwi.com"));
			post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			HttpResponse response = client.execute(post);
			HttpEntity entity = response.getEntity();
			System.out.println(response.getStatusLine());
			if(entity != null){
				System.out.println("Response content length:" +entity.getContentLength());
				String content = EntityUtils.toString(entity);
				System.out.println("Resonse content:"+content);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			client.getConnectionManager().shutdown();
		}
	}
}

0
ddatsh
ddatsh
第2个有refer 校验
0
算法与编程之美
算法与编程之美
楼上的注册不需要验证码吗?
返回顶部
顶部