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

关于c#post 请求问题。

我是论坛新人。没有积分送。


玩QQ鲜花工坊送鲜花老要自己输入送的QQ还提交两次,很麻烦想自己弄个工具自动送。写了个POST提交方法高手们帮忙看下有没问题


  public static byte[] GetHtmlByBytes(string URL, string postData, string cookie, out string header)
        {

            Encoding encoding = Encoding.GetEncoding("gb2312");
            byte[] byteRequest = encoding.GetBytes(postData);    



            long contentLength;
            HttpWebRequest httpWebRequest;
            HttpWebResponse webResponse;
            Stream getStream;

            httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
            CookieContainer co = new CookieContainer();
            co.SetCookies(new Uri("http://show.qq.com:80"), cookie);

            httpWebRequest.CookieContainer = co;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            httpWebRequest.Accept =
                "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            httpWebRequest.Referer = "http://show.qq.com/";
            httpWebRequest.UserAgent =
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; 360SE)";
            httpWebRequest.Method = "Post";
            httpWebRequest.ContentLength = byteRequest.Length;
            Stream stream;
            stream = httpWebRequest.GetRequestStream();
            stream.Write(byteRequest, 0, byteRequest.Length);
            stream.Close();
            webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            header = webResponse.Headers.ToString();
            getStream = webResponse.GetResponseStream();
            contentLength = webResponse.ContentLength;

            byte[] outBytes = new byte[contentLength];
            outBytes = ReadFully(getStream);
            getStream.Close();
            return outBytes;
        }



        public static byte[] ReadFully(Stream stream)
        {
            byte[] buffer = new byte[128];
            using (MemoryStream ms = new MemoryStream())
            {
                while (true)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                        return ms.ToArray();
                    ms.Write(buffer, 0, read);
                }
            }
        }



用抓包工具获得的数据是 发送到http://show.qq.com/cgi-bin/qqshow_flower_send 这个地址
数据是PayType=2&mail=0&signature=&flowermesg=&floweritem=3006046&flowernum=1&recvuin=331238569 --------------------编程问答-------------------- MARK,学习中
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,