//我正试着编一个qq 自动申请的东东,下边的是部分程序
//用http 协议于 qq 通信,
//可是到了获取图片验证码这里 出了一点问题
//用 sniffer 抓包,显示象qq 发送了两次 获取图片的申请
//不知何故???
//程序运行 申请失败,会显示注册码 填写错误
//请达人帮忙指点一下,下边有什么不对的地方吗?import java.net.*;
import java.io.*;public class GetImg {


private String imgPath = "E:\\qqRegImg.png";
private String num = "0.37246850717480795"; public GetImg(){
}

public GetImg(String num,String filePath){

if(num!=null&& !"".equals(num)){
this.num = num;
}
if(imgPath!=null&& !"".equals(imgPath)){
this.imgPath = imgPath;
}
}


public java.util.Collection regQQ()
throws  java.net.MalformedURLException,
java.io.IOException,
java.io.FileNotFoundException{

URL url1 = new URL ("http://freeqq2.qq.com/1.shtml");
java.net.HttpURLConnection hcn1 = (HttpURLConnection)url1.openConnection();

String coki1 = hcn1.getHeaderField("Set-Cookie");
new blog.qqUtil.qqReg.SaveCoki().doSave(coki1,"E:\\coki1.rar");
new blog.qqUtil.qqReg.SaveContent().doSave(hcn1,"E:\\page1.htm");
new blog.qqUtil.qqReg.PrintHead().doPrint(hcn1);

URL url2 = new URL ("http://freeqq2.qq.com/2.shtml");
java.net.HttpURLConnection hcn2 = (HttpURLConnection)url2.openConnection(); hcn2.setRequestProperty("Cookie",coki1);
hcn2.setRequestProperty("Referer","http://freeqq2.qq.com/1.shtml");
hcn2.connect();
String coki2 = hcn2.getHeaderField("Set-Cookie");
new blog.qqUtil.qqReg.SaveCoki().doSave(coki2,"E:\\coki2.rar");
new blog.qqUtil.qqReg.SaveContent().doSave(hcn2,"E:\\page2.htm");
new blog.qqUtil.qqReg.PrintHead().doPrint(hcn2); URL urlImg = new URL ("http://freeqq3.qq.com/getimage?"+num);
java.net.HttpURLConnection hcnImg = (HttpURLConnection)urlImg.openConnection(); hcnImg.setRequestProperty("Cookie",coki2);
hcnImg.setRequestProperty("Referer","http://freeqq2.qq.com/2.shtml");
hcnImg.connect();
System.out.println ("--------get img cookie-------------"); java.util.Collection cl = (java.util.Collection)hcnImg.getHeaderFields().get("Set-Cookie");
String cokiImg = cl.toString();
new blog.qqUtil.qqReg.SaveCoki().doSave(cokiImg,"E:\\cokiImg.rar");
new blog.qqUtil.qqReg.SaveContent().doSave(hcnImg,"E:\\pageImg.htm");
new blog.qqUtil.qqReg.PrintHead().doPrint(hcnImg); //save img
    int len = hcnImg.getContentLength();
    
InputStream is = urlImg.openStream ();
byte[] img = new byte[len+512]; //to avoid index out of bond 

int i = 0;
int ch = -1;

while ((ch = is.read ()) != -1){
img[i++] = (byte)ch;
}

File imgFile = new File(imgPath);
FileOutputStream outImg = new FileOutputStream(imgFile);
outImg.write(img);
is.close();
return cl;

}}