|  | 
 
| 163邮件的自动登陆,登陆的成功,但是登陆后他有一个跳转,登陆能够成功,但是获取cookie总是不对,下一步读取邮件内容就会出错. 
 1.邮箱首页
 
 ![1V_S~]}3PKRMZYM}[6L}AK5.png 1V_S~]}3PKRMZYM}[6L}AK5.png](data/attachment/forum/201505/19/041958sf4pukepgfrmfpfg.png)  通过对页面请求的抓取,可以看到登陆是类似
 https://mail.163.com/entry/cgi/n ... _34_660_bj&uid=邮箱地址   post请求
 postdata是如下内容:
 "savelogin=0&url2=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferror163.htm&username=用户名&password=密码
 
   
 [C#] 纯文本查看 复制代码 string html = string.Empty;
            HttpHelper http = new HttpHelper();
            HttpItem item2 = new HttpItem();
            //邮箱登陆url
            string Urlstr="https://mail.163.com/entry/cgi/ntesdoor?"
                +"df=mail163_letter"
                +"&from=web"
                +"&funcid=loginone"
                +"&iframe=1"
                +"&language=-1"
                +"&passtype=1"
                +"&product=mail163"
                +"&net=c"
                +"&style=-1"
                +"&race=-2_23_-2_hz"
                +"&uid="+ user ; 
            HttpItem item = new HttpItem()
            {
                //savelogin=0&url2=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferror163.htm&username=bearstand2015&password=76411lH123
                
                URL =Urlstr,   //URL     必需项    
                Method = "post",//URL     可选项 默认为Get   
                Referer = "http://mail.163.com/",//来源URL     可选项   
                Postdata = string.Format("savelogin=0&url2={0}&username={1}&password={2}", URLEncode(_erroLoginUrl), user,pwd),
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值  
                Allowautoredirect=true,
                AutoRedirectCookie =true,
                ResultCookieType = ResultCookieType.CookieCollection
            };
            HttpResult result = http.GetHtml(item);
            CookieCollection cookie = result.CookieCollection;
 这一步成功通过,能够看到,登陆成功
 返回一个跳装的链接
 
   
 这个页面才是真正的登陆后页面,关键正确的cookie在这里
 对这个页面我做get,页面能够获取
 
 [C#] 纯文本查看 复制代码   
            //提取登陆后邮箱地址
            Regex Rgx = new Regex(@"(?<=href = "")(.+?)(?="")", RegexOptions.IgnoreCase);
            MatchCollection mc = Rgx.Matches(result.Html);
            string LoginedUrl = string.Empty;
            foreach (Match m in mc)
            {
                LoginedUrl = m.Value.Trim();
            }
            //http://mail.163.com/js6/read/readhtml.jsp?mid=41:1tbiKQ-9fFEAOuTFoAABsM&font=15&color=064977
        //http://mail.163.com/entry/cgi/ntesdoor?df=loginjustnowmail163&funcid=loginjustnow&iframe=1
            //进入邮箱主界面
           // string Sid = HttpHelper.GetBetweenHtml(LoginedUrl,"sid=","&");
            item = new HttpItem()
           {
               //URL = "http://mail.163.com/",//URL     必需项  
               URL = LoginedUrl,
               Accept="image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, */*",
               UserAgent ="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)",
               Host  = "mail.163.com",             
               ResultCookieType = ResultCookieType.CookieCollection
           };
            result = http.GetHtml(item);
            cookie = result.CookieCollection;
   这里的cookie没取到,不知道什么情况.
 可是我用开发助手却能取到,我不明白问题在哪,麻烦大家指点一下.
 
   助手自动提取的cookie是正确的,在登陆的过程中,也能看到cookie的变化.
 
 
 | 
 |