post 数据 参考

        public Boolean VoteOnce()
        {
            //创建HttpWebRequest发送请求用
            HttpWebRequest hwrq = (HttpWebRequest)WebRequest.Create("http://www.*****.**");
            //下面是相关数据头和数据发送方法
            hwrq.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-shockwave-flash, */*";
            hwrq.Referer = "http://www.****.***";
            hwrq.ContentType = "application/x-www-form-urlencoded";
            hwrq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
            hwrq.KeepAlive = true;
            hwrq.Method = "POST";
            //下面发送数据,使用MiniSniffer来抓包分析应该发送什么数据
            string PostStr = "username=*****&password=******&styleid=&referer=www.*******";
            ASCIIEncoding ASC2E = new ASCIIEncoding();
            byte[] bytePost = ASC2E.GetBytes(PostStr);//把要发送的数据变成字节
            hwrq.ContentLength = bytePost.Length;
            //下面是发送数据的字节流
            Stream MyStream = hwrq.GetRequestStream();
            MyStream.Write(bytePost, 0, bytePost.Length);
            MyStream.Close();//记得要结束字节流啊
            //创建HttpWebResponse实例
            HttpWebResponse hwrp = (HttpWebResponse)hwrq.GetResponse();
            StreamReader MyStreamR = new StreamReader(hwrp.GetResponseStream(), Encoding.Default);
            string result = MyStreamR.ReadToEnd();
            Boolean r = false;
            if (Regex.IsMatch(result, "欢迎您回来") == true)
            {
                r = true;
            }
            MyStreamR.Close();
            return r;
        }

posted @ 2010-04-08 11:15  道勋  阅读(241)  评论(0编辑  收藏  举报