C#验证码模拟登录的时候下载到的验证码错误
大家帮忙啊,我最近在搞C#验证码模拟登录,登录联通网上营业厅。http://wwww.10010.com/login.jsp
我采用半自动的方式下载到验证码,然后自己填写,然后提交,可是返回值总说验证码错误,请大侠指教啊!
//模拟登录
private void btnLogin_Click(object sender, EventArgs e)
{
string checkCode = textValidateCode.Text;
string postUrl = "http://www.10010.com/login/userLogin.action";
string postData = "loginInfo.userName=手机号&loginInfo.password=密码&loginInfo.check_code=" + checkCode + "&loginInfo.UniTokenRequest=null&loginInfo.returnURL=&loginInfo.areaNumber=&loginInfo.loginType=01&MobileUserName=手机号&loginInfo.identifyType=01&MobilePassword=密码&RandomPassword=&MobileCheckCode=" + checkCode + "&FixAreaNumber=%D6%D0%CE%C4%2F%C6%B4%D2%F4&FixUserName=%CE%DE%D0%E8%CA%E4%C8%EB%C7%F8%BA%C5%A3%A1&FixPassword=&FixCheckCode=%B5%E3%BB%F7%BB%F1%C8%A1&TeleAreanumber=%D6%D0%CE%C4%2F%C6%B4%D2%F4&TeleUserName=%CE%DE%D0%E8%CA%E4%C8%EB%C7%F8%BA%C5%A3%A1&TelePassword=&TeleCheckCode=%B5%E3%BB%F7%BB%F1%C8%A1&ADSLAreaNumber=%D6%D0%CE%C4%2F%C6%B4%D2%F4&ADSLUserName=%CE%DE%D0%E8%CA%E4%C8%EB%C7%F8%BA%C5%A3%A1&ADSLPassword=&ADSLCheckCode=%B5%E3%BB%F7%BB%F1%C8%A1&LANAreanumber=%D6%D0%CE%C4%2F%C6%B4%D2%F4&LANUserName=%CE%DE%D0%E8%CA%E4%C8%EB%C7%F8%BA%C5%A3%A1&LANPassword=&LANCheckCode=%B5%E3%BB%F7%BB%F1%C8%A1&WebUserName=%C4%FA%D7%A2%B2%E1%B5%C4%D3%CA%CF%E4&WebPassword=&WebCheckCode=%B5%E3%BB%F7%BB%F1%C8%A1";
//string ydData="submitMode=2&ErrorUrl=..%2FbriefLogon.do&ReturnURL=www.sd.10086.cn%2Fportal%2Fgxhzq%2Findex.jsp&FieldID=1&entrance=IndexBrief&mobileNum=手机号&logonMode=1&servicePWD=******&randCode="+checkCode+"&smsRandomCode=";
string strr = Http.GetHtml(postUrl, postData, aspcookie, out header);
FileStream fst = new FileStream("D:\\0.htm", FileMode.Append);
StreamWriter swt = new StreamWriter(fst, Encoding.GetEncoding("utf-8"));
//写入
swt.WriteLine(strr);
swt.Close();
fst.Close();
}
//下载验证码
private void btnGetCode_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.10010.com/getImage.jsp");
request.CookieContainer = co;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();//得到验证码数据流
Bitmap sourcebm = new Bitmap(resStream);//初始化Bitmap图片
picValidateCode.Image = sourcebm;
}
CookieCollection Cookie = null;
//获取登录页面cookie
private void btnGetPage_Click(object sender, EventArgs e)
{
HttpWebRequest httpWebRequest;
HttpWebResponse webResponse;
//获取页面cookie
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.10010.com/login.jsp");
co.SetCookies(new Uri("http://www.10010.com"), cookie);
httpWebRequest.CookieContainer = co;
webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
//getStream = webResponse.GetResponseStream();
Cookie = webResponse.Cookies;
header = webResponse.Headers.ToString();//返回头文件
header = webResponse.Headers.Get("Set-Cookie");//返回Cookie
MessageBox.Show(header);
}