StartGet(); //取SID
long TCheckCode = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;//CheckCode(TCheckCode, textBox1.Text);
Encoding mye= Encoding.GetEncoding("utf-8");
HttpWebRequest myReq= (HttpWebRequest)WebRequest.Create("http://reg.jiayuan.com/libs/xajax/reguser.server.php?processTraceUser");string s = "xajax=processTraceUser&xajaxargs%5B%5D=%3Cxjxquery%3E%3Cq%3Evalidate_code%3D" + textBox1.Text + "%3C%2Fq%3E%3C%2Fxjxquery%3E&xajaxargs%5B%5D=validate_code&xajaxr=" +TCheckCode;byte[] arrB =mye.GetBytes(s);
myReq.Method= "post";
myReq.Accept= "*/*";
myReq.ContentLength=s.Length;
myReq.Headers.Set("x-requested-with", "XMLHttpRequest");
myReq.Headers.Set("Accept-Encoding", "gzip, deflate");
myReq.Headers.Set("Accept-Language", "zh-cn");
myReq.Headers.Set("Cache-Control", "no-cache");
myReq.Headers.Set("sid", SID);
myReq.Headers.Set("Cookie", "cookie");
myReq.ContentType= "application/x-www-form-urlencoded";
myReq.Referer= "http://reg.jiayuan.com/signup/fillbasic.php?bd=204";
myReq.UserAgent= "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; .NET4.0C; .NET4.0E; 360SE)";//myReq.KeepAlive = true;//if (cc.Count == 0)//{//myReq.CookieContainer = new CookieContainer();//新建一个杯子//cc = myReq.CookieContainer;//指定拿起这个杯子//}//else//{//myReq.CookieContainer = cc;//}
Stream outStream=myReq.GetRequestStream();
outStream.Write(arrB,0, arrB.Length);
outStream.Close();
HttpWebResponse myResp= null;try{//接收HTTP做出的响应
myResp =(HttpWebResponse)myReq.GetResponse();
}catch(Exception err)
{
MessageBox.Show(err.Message);
}
Stream ReceiveStream=myResp.GetResponseStream();
StreamReader readStream= newStreamReader(ReceiveStream, mye);
Char[] read= new Char[256];int count = readStream.Read(read, 0, 256);string str = null;while (count > 0)
{
str+= new String(read, 0, count);
count= readStream.Read(read, 0, 256);
}//myReq.CookieContainer = cc;//foreach (Cookie cookie in myResp.Cookies)//把服务器给我们的很多滴水,收集放到杯子里面//{//cc.Add(cookie);//}
readStream.Close();
myResp.Close();if (str.Contains("验证码填写错误"))
{
richTextBox1.Text=str;
}else if (str.Contains("CDATA[show exactness"))
{
richTextBox1.Text= "验证码输入正确";
}
}