|
楼主 |
发表于 2013-6-4 01:26:02
|
显示全部楼层
老大,终于成功了,研究了一天呐,同时推荐一篇非常不错的文章,对我启迪很大啊:http://www.cnblogs.com/top5/archive/2010/04/11/1709457.html下面再贴一下源码,希望以后遇到同样问题的人可以解决
[code=csharp] #region 取文本中间
public static string qwbzj(string str, string str1, string str2)
{
Regex regex = new Regex(string.Format("(?<={0}).*?(?={1})", str1, str2), RegexOptions.Compiled);
Match match = regex.Match(str);
if (match.Success)
{
return match.Value;
}
return string.Empty;
}
#endregion
#region 取MD5
string md5(string str)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string s = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(str)));
s = s.Replace("-", "");
return s.ToLower();
}
#endregion
string loginmama(string zhanhao,string mima)
{
//获取token值
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
UserAgent="Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0",
Accept="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
URL = "http://www.alimama.com/index.htm",
};
HttpResult result = http.GetHtml(item);
//开始登录
HttpItem item1 = new HttpItem()
{
UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20100101 Firefox/21.0",
Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
ContentType = "application/x-www-form-urlencoded",
Referer = "http://www.alimama.com/member/minilogin.htm?&proxy=http://www.alimama.com/proxy.htm",
Cookie = result.Cookie,
Method = "post",
URL = "http://www.alimama.com/member/minilogin_act.htm",
Postdata = "_tb_token_=" + qwbzj(result.Cookie, "_tb_token_=", ";") + "&style=&redirect=&proxy=http%3A%2F%2Fwww.alimama.com%2Fproxy.htm&logname=" + zhanhao + "&originalLogpasswd=" + mima + "&logpasswd=" + md5(mima)
};
HttpResult result1 = http.GetHtml(item1);
//string ccc = result1.Cookie;
q_cookies = result.Cookie;//由于登录成功之后是302转向(好像就不会返回任何cookies,之前这里也卡了一下),所以这里直接再次取一下之前的cookies
//这里的q_cookies是我设置的全局变量,用于以后调用
return "";
}
[/code]
|
|