日期:2014-05-17  浏览次数:20727 次

腾讯微博模拟登录输入验证码问题
***先上代码, 大致功能是模拟登录 然后把cookie存到文件中。
***鄙人设置每登录一个帐号 休息5秒 大概10个左右 就开始要我输入验证码了。
***我将验证码存到D盘,然后查看图片 手动输入验证码 。
***但是一直会出现

1/ij2l5G6GHA555nGImjODZB1tXgo_KFAl/\x00\x00\x00\x00\x33\x78\x0e\x75
需要输入验证码
http://captcha.qq.com/getimage?uin=863506037&aid=46000101&0.11248807175794862
请输入验证码:
numk
测试结果:ptuiCB('7','0','','0','很遗憾,网络连接出现异常,请您稍后再试。(2237663584)', '0');

一直是异常,感觉上这个像是访问过快被封了,但是又有人说是cookie 或者参数传的不对,求高手帮忙看看哪里有问题??(注:不出验证码提示的时候,我程序是ok的。)


/********************* 获取验证码 ***********************/
String codeUrl="http://check.ptlogin2.qq.com/check?uin="+ uin + "&appid=46000101&ptlang=2052&r=" + Math.random();
HttpGet get = new HttpGet(codeUrl);
get.setHeader("Host", "check.ptlogin2.qq.com");
get.setHeader("Referer", "http://t.qq.com/?from=11");
get.setHeader("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
HttpResponse response = client.execute(get);
// HttpResponse response = client.execute(proxy,get);

String entity = EntityUtils.toString(response.getEntity());
String[] checkNum = entity.substring(entity.indexOf("(") + 1,entity.lastIndexOf(")")).replace("'", "").split(",");
String checkCode = checkNum[1];
System.out.println(checkNum[0]+"/"+checkNum[1]+"/"+checkNum[2]);
if(checkNum[0].equals("1")){
System.out.println("需要输入验证码");

String str12 = "http://captcha.qq.com/getimage?uin="+uin+"&aid=46000101&0.11248807175794862";
System.out.println(str12);
URL   url   =   new   URL(str12);                         
URLConnection   uc   =   url.openConnection();                         
InputStream   is   =   uc.getInputStream();                         
File   file   =   new   File("D:/QQwocaonidaye.jpg");                         
FileOutputStream   out   =   new   FileOutputStream(file);                         
int  j =0;                         
while   ((j=is.read())!=-1) {                                 
out.write(j);                         
}