日期:2014-05-20  浏览次数:20810 次

求一C#winform自动登陆论坛获取论坛源码的例子。。
小弟初学C#
在网上看了好多利用httpwebrequest  自动登陆的帖子。。可是看不大明白。
请大神 给个简单易懂的例子。。
求一C#winform自动登陆论坛获取论坛源码的例子。。
------最佳解决方案--------------------
引用:
哥们。。。我的意思是 只需要模拟登陆就可以了,,,  这方面找老好久 没找到。。。


        private string accept = "*/*";
        private string contentType = "application/x-www-form-urlencoded";
        private string refer = "http://space.yuanchuang.com/account/login?ReturnUrl=http%3A//bbs.yuanchuang.com/forum.php";
        private string userAgent = "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1171.0 Safari/537.1";
        private CookieContainer cookies = new CookieContainer();

        private void button1_Click(object sender, EventArgs e)
        {         
            string forWard = "http://bbs.yuanchuang.com/forum.php";
            string userName = "123456"; //帐号
            string passWord = "123456;  //密码
            string url = "http://space.yuanchuang.com/account/login";
            string postData = string.Format("forward={0}&username={1}&password={2}", forWard, userName, passWord);
            textBox1.Text = GetPost(url, "post", postData);//获取源代码
        }

        #region 获取数据方法
        public string GetPost(string url, string method, string data)
        {
            Uri uri = new Uri(url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.UserAgent = this.userAgent;
            request.Accept = this.accept;
            request.ContentType = this.contentType;
            request.Method = method;
            request.Referer = this.refer;
            request.CookieContainer = this.cookies;
            if (method.Equals("post"))
            {
                byte[] byteRequest = Encoding.Default.GetBytes(data);