我想模拟163用户登录,通过了抓包分析得到路径(我不能确保我的分析是否正确)希望有人能帮忙分析一下,新手上路。。。我的主要代码如下:
private void GetCookies()
{
string username = "lstcJaney@163.com";
string password = "08339314lry";
string url2 = "http://email.163.com/errorpage/err_163.htm";
CookieContainer myCookieContainer = new CookieContainer();
string indata = string.Empty;
string url = "https://ssl.mail.163.com/entry/coremail/fcg/ntesdoor2?funcid=loginone&language=-1&passtype=1&iframe=1&product=mail163&from=web&df=email163&module=&uid=lstcJaney@163.com&style=-1";
indata = "username=" + username + "&url2=" + url2 + "&savelogin=0&password=" + password;
PostData(url, indata, myCookieContainer);
url = "http://uinfo.mail.163.com/contactproxy/getbdayinfo.do?uid=lstcjaney@163.com&view=bdayinfo_client";
string backurl = "http://webmail.mail.163.com/app/api/service_backurl.jsp?sid=rBWPCXagzGnwJNrZhqggNMrsNUgAxNEN&callback=parent.$I('product.Gift').load";
indata = "fids=" + username.ToLower() + "&backurl=" + backurl;
PostData(url, indata, myCookieContainer);
//url = "http://webmail.mail.163.com/app/api/service_backurl.jsp?sid=rBWPCXagzGnwJNrZhqggNMrsNUgAxNEN&callback=parent.$I('product.Gift').load";
//indata = "contact={\"code\":\"201\",\"pcode\":\"201\"}";
//PostData(url, indata, myCookieContainer);
this.webBrowser1.Navigate("http://webmail.mail.163.com/js4/main.jsp?sid=vAtsbBlJTLQGVIsrTjJJyajpYIEXuJOr#module=welcome.WelcomeModule");
}
/// <summary>
/// Post数据
/// </summary>
/// <param name="url"></param>
/// <param name="indata"></param>
/// <param name="myCookieContainer"></param>
/// <returns></returns>
public static string PostData(string url, string indata, CookieContainer myCookieContainer)
{
string outdata = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.ContentLength = indata.Length;
myHttpWebRequest.Method = "POST";
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; 360SE)";
myHttpWebRequest.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, */*";
myHttpWebRequest.CookieContainer = myCookieContainer;
try
{
Stream myRequestStream = myHttpWebRequest.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(indata);
myStreamWriter.Close();
myRequestStream.Close();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
//myCookieContainer = myHttpWebRequest.CookieContainer;
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
outdata = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
}
catch (Exception ex)
{
}
return outdata;
}
代码也不先格式化一下!
哥们,你也不怕别人拿你的邮箱干坏事。