当前位置:编程学习 > C#/ASP.NET >>

一个简单网站登录错误,麻烦帮指正下!

最近想写个自动登录软件,怎奈是个小白,网上查了一大堆资料也没搞定,希望哪位大侠帮着看看!
private void Form1_Load(object sender, EventArgs e)
        {
            string str;
            string postData;
            postData = "user=1060421**&pass=62839****&ip=172.20.15.210&type=2&action=%C1%AC%BD%D3%CD%F8%C2%E7";
            str=SendMsg(postData);
            textBox1.Text = str;
        }
        public string SendMsg(string postData)
        {  
                string url = "http://121.195.254.46/index.jsp";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";
                request.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
                request.Referer = "http://121.195.254.46/index.jsp";
                request.AllowAutoRedirect = true;
                request.KeepAlive = true;
                request.SendChunked = true;
                request.ContentType = "text/html;charset=gb2312;";
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
                request.ContentType = "application/x-www-form-urlencoded";
                request.KeepAlive = true;
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
                byte[] data = Encoding.GetEncoding("GB2312").GetBytes(postData);
                request.ContentLength = data.Length;
                MessageBox.Show(Convert .ToString(data.Length));
                Stream stream = request.GetRequestStream();
                stream.Write(data, 0, data.Length);
                stream.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("GB2312"));
                string s = sr.ReadToEnd();
                response.Close();
                return s;
         }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,