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;
//提取登陆后邮箱地址
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;