毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

C#验证码模拟登录验证码错误

更新时间:2014-1-8:  来源:毕业论文

我采用半自动的方式下载到验证码,然后自己填写,然后提交,可是返回值总说验证码错误,请大侠指教啊!
 //模拟登录         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);         }

验证码cookie不一致

CookieContainer cookie;
        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;
           cookie.Add(response.Cookies);  
  resStream.Close();
response.Close();
 
  }

 Http.GetHtml(postUrl, postData, aspcookie, out header);
把cookie传过去,设置登录附加cookie
 request.CookieContainer = cookie;

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。