日期:2014-05-17  浏览次数:21115 次

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);