winFrom qq空间登录

bombw 2010-05-13 07:04:13
在网上翻出的登录qq空间资料,但并不能正确登录空间,如何才能正确的登录到QQ空间?

http请求方法

/// <summary>
/// 获取指定页面的HTML代码
/// </summary>
/// <param name="url">指定页面的路径</param>
/// <param name="postData">回发的数据</param>
/// <param name="isPost">是否以post方式发送请求</param>
/// <param name="cookieCollection">Cookie集合</param>
/// <returns></returns>
public string GetHtml(string url, string postData, bool isPost, CookieContainer cookieContainer)
{
if (string.IsNullOrEmpty(postData))
{
return GetHtml(url, cookieContainer);
}

Thread.Sleep(NetworkDelay);

currentTry++;

try
{
byte[] byteRequest = Encoding.Default.GetBytes(postData);

HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = isPost ? "POST" : "GET";
httpWebRequest.ContentLength = byteRequest.Length;

Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();

HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();

currentTry = 0;
return html;
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message);
Console.ForegroundColor = ConsoleColor.White;

if (currentTry <= maxTry)
{
GetHtml(url, postData, isPost, cookieContainer);
}

currentTry = 0;
return string.Empty;
}
}

/// <summary>
/// 获取指定页面的HTML代码
/// </summary>
/// <param name="url">指定页面的路径</param>
/// <param name="cookieCollection">Cookie集合</param>
/// <returns></returns>
public string GetHtml(string url, CookieContainer cookieContainer)
{
Thread.Sleep(NetworkDelay);

currentTry++;

try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = "GET";

HttpWebResponse httpWebResponse;
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, encoding);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();

currentTry = 0;
return html;
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss ") + e.Message);
Console.ForegroundColor = ConsoleColor.White;

if (currentTry <= maxTry)
{
GetHtml(url, cookieContainer);
}

currentTry = 0;
return string.Empty;
}
}


登录代码
/// <summary>
/// 登录
/// </summary>
/// <param name="loginEmail">用户名</param>
/// <param name="loginPassword">密码</param>
/// <returns></returns>
public bool Login(string username, string userPWD, string strTemp, System.Windows.Forms.HtmlDocument doc, out string errorTxt)
{
HttpHelper httpHelper = new HttpHelper();
string strRetVal = "";
HtmlDocument doc1 = doc;
if (doc1 == null)
{
errorTxt = "加载必要控件失败,请重新开启软件";
return false;
}
strRetVal = (string)doc1.InvokeScript("md5_3", new object[] { userPWD });
strRetVal += strTemp.ToUpper();
strRetVal = (string)doc1.InvokeScript("md5", new object[] { strRetVal });
string postData = "u=" + username + "&p=" + strRetVal + "&verifycode=" + strTemp + "&aid=15000101&u1=http%3A%2F%2Fphp.qzone.qq.com%2Findex.php%3Fmod%3Dportal%26act%3Dlogin&fp=loginerroralert&h=1&ptredirect=1&ptlang=0&from_ui=1&dumy=";
string result = httpHelper.GetHtml("http://ptlogin2.qq.com/login", postData, true, cookie);
errorTxt = result;
result = httpHelper.GetHtml("http://php.qzone.qq.com/index.php?mod=portal&act=login", cookie);

bool isLogin = result.Contains("g_iLoginUin = " + username);
if (!isLogin)
{

if (result.Contains("完成跳转"))
{
isLogin = true;

}
if (!isLogin)
{
isLogin = result.Contains("g_iLoginUin=" + username);
}
}

return isLogin;
}


返回的页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>QQ社区登录</title>
<style>
body{ font:"宋体",Arial, Helvetica, sans-serif; font-size:14px; line-height:25px;}
.wrong{ width:auto; margin:0 auto; padding:20px; background:#F0F0F0; border:#CCCCCC solid 1px;}
h2{ color: #FF0000 ; font-size:16px; }
.STYLE1 {color: #FF3300}
</style>
<script language="javascript">
document.domain="qq.com"
function timeelapse(){
top.location.href='http://php.qzone.qq.com/index.php?mod=portal&act=login';
}
timeelapse();
</script>
</head>
<body>
<div class="wrong" >
如果未能自动跳转,请<a href="http://php.qzone.qq.com/index.php?mod=portal&act=login" target="_top">点击</a>完成跳转。</div>
</body>
</html>



如何才能正确的登录到QQ空间?
...全文
893 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
理不完的逻辑 2010-05-13
  • 打赏
  • 举报
回复
顶 学习~!
studentliudong 2010-05-13
  • 打赏
  • 举报
回复
不会,帮楼主置顶~~
mayonglong 2010-05-13
  • 打赏
  • 举报
回复
学习~
waitdream 2010-05-13
  • 打赏
  • 举报
回复
整个登陆过程并不难,无非就是POST一个数据过去~重点在加密密码的模块~加密算法腾讯的JS文件里面有~把那个算法改成C#的用点复杂~所以我一般是直接用WB控件调用JS处理加密后的密码在登陆~

110,578

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧