C# 已经实现模拟登录(可以获得登录后的html),怎样实现打开一个登录后的页面
public class HttpHelper
{
public static CookieContainer Cookies = new CookieContainer();
public static string GetHttpResponse(string url, string postdata)
{
try
{
HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create(url);
MyRequest.Method = "POST";
MyRequest.ContentLength = postdata.Length;
MyRequest.CookieContainer = Cookies;
MyRequest.KeepAlive = true;
MyRequest.AllowAutoRedirect = true;
MyRequest.ContentType = "application/x-www-form-urlencoded";
MyRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1";
MyRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
if (postdata != null)
{
ASCIIEncoding MyEncoding = new ASCIIEncoding();
byte[] MyByte = MyEncoding.GetBytes(postdata);
Stream MyStream = MyRequest.GetRequestStream();
MyStream.Write(MyByte, 0, postdata.Length);
MyStream.Close();
}
string getContent = null;
Encoding myEncoding = Encoding.GetEncoding("UTF-8");
HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse();
if (MyResponse.StatusCode == HttpStatusCode.OK)
{
/*获取响应页面cookie*/
// MyResponse.Cookies = MyRequest.CookieContainer.GetCookies(MyRequest.RequestUri);
MessageBox.Show("adfdfasdf");
Stream MyNewStream = MyResponse.GetResponseStream();
StreamReader MyStreamReader = new StreamReader(MyNewStream, myEncoding);
getContent = MyStreamReader.ReadToEnd();
MyStreamReader.Close();
}
MyResponse.Close();
return getContent;
}
catch (Exception)
{
return string.Empty;
}
}
}