private void startEnter()
{
//调用以上的方法来获取需要登录才能查看的内容。
CookieContainer cc = new CookieContainer();
cc = Get_SinaLogin(); //获取登录Cookies
string PhotoClassURL = "http://blog.sina.com.cn/myblog/htmlsource/blog_notopen.php?uid=1639008895";
HttpWebRequest Myrequest = (HttpWebRequest)WebRequest.Create(PhotoClassURL);
Myrequest.CookieContainer = cc;
HttpWebResponse Myresponse = (HttpWebResponse)Myrequest.GetResponse();
cc.Add(Myresponse.Cookies);
Stream Mystream = Myresponse.GetResponseStream();
string sHtml = new StreamReader(Mystream, System.Text.Encoding.UTF8).ReadToEnd();
//sHtml即为你登录之后看到的内容.
// MessageBox.Show(sHtml);
this.TextBox2.Text = sHtml;
for (int i = 0; i < Request.QueryString.AllKeys.Length; i++)
{
Response.Write(Request.QueryString.AllKeys[i] + "<br>");
}
}
public static CookieContainer Get_SinaLogin()
{
CookieContainer cc = new CookieContainer();
string FormURL = "http://my.blog.sina.com.cn/login.php?index=index&type=new"; //处理表单的绝对URL地址
string FormData = "loginname=youname&passwd=youpassword"; //表单需要提交的参数,注意改为你已注册的信息。
Encoding encoding = Encoding.UTF8;
byte[] data = encoding.GetBytes(FormData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormURL);
request.Method = "POST"; //数据提交方式
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
//模拟一个UserAgent
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
request.CookieContainer = cc;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cc.Add(response.Cookies);
Stream stream = response.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd();
return cc;
}