[求助]C# WinForm登录百度

oktell 2010-01-13 03:52:04
最近,做了个百度“阳光牧场”网页游戏的外挂,其中的核心环节是“登录”,在一个月以前,我的外挂能正常运行,可最近一段时间,不能正常登录了,现在我将我的登录部分贴出来,请求高手帮我看一下。谢谢。

HTTP请求类

using System;
using System.Net;
using System.IO;
using System.Text;

namespace Farm
{
/// <summary>
/// HTTP请求类
/// </summary>
public class MyHttp
{
public MyHttp()
{
}

#region 通过Post方式发送数据
/// <summary>
/// 通过Post方式发送数据
/// </summary>
/// <param name="Url">Url</param>
/// <param name="postDataStr">Post数据</param>
/// <param name="cookie">cookie</param>
/// <returns>返回数据</returns>
public static string SendDataByPost(string Url, string postDataStr, ref CookieContainer cookie)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
if (cookie.Count == 0)
{
request.CookieContainer = new CookieContainer();
cookie = request.CookieContainer;
}
else
{
request.CookieContainer = cookie;
}

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// new Add
//request.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
request.ContentLength = postDataStr.Length;
Stream myRequestStream = request.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
string retString= myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

return retString;
}
catch
{
return "";
}
}
#endregion

#region 同步通过GET方式发送数据
/// <summary>
/// 通过GET方式发送数据
/// </summary>
/// <param name="Url">url</param>
/// <param name="postDataStr">GET数据</param>
/// <param name="cookie">GET容器</param>
/// <returns></returns>
public static string SendDataByGET(string Url, string postDataStr, ref CookieContainer cookie)
{
string sendurl = Url +(postDataStr == "" ? "" : "?") + postDataStr;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sendurl);
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url +(postDataStr == "" ? "" : "?") + postDataStr);
if (cookie.Count == 0)
{
request.CookieContainer = new CookieContainer();
cookie = request.CookieContainer;
}
else
{
request.CookieContainer = cookie;
}

request.Method = "GET";
request.ContentType = "text/html;charset=utf-32";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

return retString;
}
#endregion

}
}



登录方法

private bool LoginGame(string name, string pwd)
{
string Url0 = "https://passport.baidu.com/?login&tpl=sp&tpl_reg=spsp&u=http%3A%2F%2Fapps.hi.baidu.com%2Fsunfarm";
string Url1 = "https://passport.baidu.com/?login";
string Url2 = "http://apps.hi.baidu.com/sunfarm";
string Url3 = "http://sunfarm.baiduapp.com";
string Url4 = "http://sunfarm.baiduapp.com/embed_swf/";
string KeyWord = "session_name=sessionid";
string SesssionIdKeyWord = "session_value=";
string UidKeyWord = "uid=";
string strRet = "";

CommandParams cpm = this.GetLoginParams(name, pwd);
CookieContainer cc = new CookieContainer();

strRet = MyHttp.SendDataByGET(Url1, cpm.Cp, ref cc);
//strRet = MyHttp.SendDataByPost(Url1, cpm.Cp, ref cc);
//WriteLog("Length:" + strRet.Length.ToString());
//WriteLog(strRet);
if (strRet.IndexOf(Url2) == -1)
{
return false;
}

try
{
strRet = MyHttp.SendDataByGET(Url2, "", ref cc);
//WriteLog(strRet);
if (strRet.IndexOf(Url3) == -1)
{
return false;
}

string UrlData1 = AnalyzingHtmlCode(strRet);
//WriteLog(UrlData1);
strRet = MyHttp.SendDataByGET(Url3, UrlData1, ref cc);
//WriteLog(strRet);
if (strRet.IndexOf(Url4) == -1)
{
return false;
}

string UrlData2 = AnalyzingHtmlCode(strRet, Url4);
//WriteLog(UrlData2);
strRet = MyHttp.SendDataByGET(Url4, UrlData2, ref cc);
//WriteLog(strRet);
if (strRet.IndexOf(KeyWord) == -1)
{
return false;
}
else
{
this.SessionId = Tools.GetValueByKey(strRet, SesssionIdKeyWord, "&", "\"").Replace(SesssionIdKeyWord, "");
this.Uid = Tools.GetValueByKey(strRet, UidKeyWord, "&", "\"").Replace(UidKeyWord, "");
}
}
catch
{
return false;
}

return true;
}

...全文
802 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
srxljl 2011-01-17
  • 打赏
  • 举报
回复
PostData = "tpl_ok=&next_target=&tpl=&skip_ok=&aid=&need_pay=&need_coin=&pay_method=&u=.%2F&return_method=get&more_param=&return_type=&psp_tt=0&password=" + HttpUtility.UrlEncode(UserPass, PG.MyCode) + "&safeflg=0&username=" + HttpUtility.UrlEncode(UserName, PG.MyCode) + "&verifycode=" + HttpUtility.UrlEncode(UserYZM.Trim(), PG.MyCode);
WebCodes = PG.PostDataSSL("https://passport.baidu.com/?login", "http://hi.baidu.com", PostData, "POST", UserCookie, "");
srxljl 2011-01-17
  • 打赏
  • 举报
回复
百度登陆,我过去的代码可以登陆,没有问题,重新写的不行,但是现在拿出旧代码就可以登陆,保证没有问题。
zzkk25 2010-01-19
  • 打赏
  • 举报
回复
外挂,支持
geniusatm4 2010-01-18
  • 打赏
  • 举报
回复
参观
cc2563 2010-01-18
  • 打赏
  • 举报
回复
学习
zhang8xiao8liang 2010-01-18
  • 打赏
  • 举报
回复
帮顶
不老神仙 2010-01-18
  • 打赏
  • 举报
回复
帮顶 
snowkingdom 2010-01-18
  • 打赏
  • 举报
回复
学习的 看来对外挂感兴趣的人还真多
oktell 2010-01-18
  • 打赏
  • 举报
回复
自己顶一下。
  • 打赏
  • 举报
回复
分析每一步的登陆过程.一个HTTP请求类
oktell 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 wisecameo 的回复:]
我和楼主遇上了同样的问题,一起想办法吧。另楼主用的什么捉包工具?加我QQ535615299聊吧
[/Quote]

我用的是HttpWatch。
shixh7 2010-01-14
  • 打赏
  • 举报
回复
学习,帮顶吧
yxfreeman520 2010-01-14
  • 打赏
  • 举报
回复
mark
U2008 2010-01-14
  • 打赏
  • 举报
回复
HttpAnalyzerStdV3


专业的捉包工具。。
WuZongBo 2010-01-14
  • 打赏
  • 举报
回复
http://blog.csdn.net/sckoo/archive/2010/01/02/5122741.aspx
owenliangbin 2010-01-14
  • 打赏
  • 举报
回复
建议问一下百度。
oktell 2010-01-14
  • 打赏
  • 举报
回复
自己顶了。还希望有实质性的帮助啊。
balancenada 2010-01-13
  • 打赏
  • 举报
回复
很厉害
wzuomin 2010-01-13
  • 打赏
  • 举报
回复
这方面不是很懂,帮顶吧
wisecameo 2010-01-13
  • 打赏
  • 举报
回复
我和楼主遇上了同样的问题,一起想办法吧。另楼主用的什么捉包工具?加我QQ535615299聊吧
加载更多回复(14)

110,533

社区成员

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

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

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