Ejemplo n.º 1
0
        public static byte[] GetBypes(RequestArgs mReq)
        {
            byte[]     array = null;
            GZipStream stream3;

            byte[]         buffer3;
            bool           flag;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mReq.Url);

            request.Method    = mReq.Method;
            request.Accept    = "*/*";
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            if (mReq.cookie != string.Empty)
            {
                request.Headers.Add(HttpRequestHeader.Cookie, mReq.cookie);
            }
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            request.KeepAlive = true;
            if (mReq.RefererUrl != "")
            {
                request.Referer = mReq.RefererUrl;
            }
            request.AllowAutoRedirect = mReq.blRedirect;
            if (mReq.blPolicy)
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CWebRequest.CheckValidationResult);
            }
            if (mReq.Method == "POST")
            {
                StreamWriter writer = null;
                writer = new StreamWriter(request.GetRequestStream());
                writer.Write(mReq.postData);
                writer.Close();
            }
            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            Stream          responseStream = response.GetResponseStream();

            byte[] buffer = new byte[0x7d000];
            int    num    = 0;
            int    offset = 0;

            while (true)
            {
                flag = true;
                num  = responseStream.Read(buffer, offset, buffer.Length - offset);
                if (num <= 0)
                {
                    if (!(response.ContentEncoding == "gzip"))
                    {
                        array = new byte[offset];
                        for (int i = 0; i < offset; i++)
                        {
                            array[i] = buffer[i];
                        }
                        goto Label_0235;
                    }
                    MemoryStream stream = new MemoryStream(buffer, 0, offset, true);
                    stream3 = new GZipStream(stream, CompressionMode.Decompress, true);
                    stream.Seek(0L, SeekOrigin.Begin);
                    buffer3 = new byte[0x4b000];
                    offset  = 0;
                    break;
                }
                offset += num;
            }
Label_01E8:
            flag = true;
            num  = stream3.Read(buffer3, offset, 0x400);
            if (num == 0)
            {
                stream3.Close();
                array = new byte[offset];
                buffer3.CopyTo(array, offset);
            }
            else
            {
                offset += num;
                goto Label_01E8;
            }
Label_0235:
            request.Abort();
            response.Close();
            return(array);
        }
Ejemplo n.º 2
0
        public static string GetPost(RequestArgs mReq)
        {
            HttpWebResponse response;
            GZipStream      stream3;

            byte[]         buffer2;
            string         str2;
            bool           flag;
            string         str     = "";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mReq.Url);

            request.Method = mReq.Method;
            request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*";
            if (string.IsNullOrEmpty(mReq.charset))
            {
                request.ContentType = "text/xml; charset=utf-8";
            }
            else
            {
                request.ContentType = "text/xml; charset=utf-8";
            }
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            if (mReq.cookie != string.Empty)
            {
                request.Headers.Add(HttpRequestHeader.Cookie, mReq.cookie);
            }
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            request.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-cn");
            request.KeepAlive = true;
            if (mReq.RefererUrl != "")
            {
                request.Referer = mReq.RefererUrl;
            }
            request.AllowAutoRedirect = mReq.blRedirect;
            if (mReq.blPolicy)
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CWebRequest.CheckValidationResult);
            }
            if (mReq.Method == "POST")
            {
                StreamWriter writer = null;
                writer = new StreamWriter(request.GetRequestStream());
                writer.Write(mReq.postData);
                writer.Close();
            }
            Encoding encoding = Encoding.UTF8;
            string   str5     = mReq.Encode.ToUpper();

            if (str5 != null)
            {
                if (!(str5 == "UTF-8"))
                {
                    if (str5 == "GB2312")
                    {
                        encoding = Encoding.GetEncoding("gb2312");
                        goto Label_01DA;
                    }
                    if (str5 == "BIG5")
                    {
                        encoding = Encoding.GetEncoding("BIG5");
                        goto Label_01DA;
                    }
                }
                else
                {
                    encoding = Encoding.UTF8;
                    goto Label_01DA;
                }
            }
            encoding = Encoding.GetEncoding("gb2312");
Label_01DA:
            response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();

            if (!(response.ContentEncoding == "gzip"))
            {
                StreamReader reader = new StreamReader(responseStream, encoding);
                str = reader.ReadToEnd();
                reader.Close();
                goto Label_02E9;
            }
            byte[] buffer = new byte[0x19000];
            int    num    = 0;
            int    offset = 0;

            while (true)
            {
                flag = true;
                num  = responseStream.Read(buffer, offset, buffer.Length - offset);
                if (num <= 0)
                {
                    MemoryStream stream = new MemoryStream(buffer, 0, offset, true);
                    stream3 = new GZipStream(stream, CompressionMode.Decompress, true);
                    stream.Seek(0L, SeekOrigin.Begin);
                    buffer2 = new byte[0x4b000];
                    offset  = 0;
                    break;
                }
                offset += num;
            }
Label_02B1:
            flag = true;
            num  = stream3.Read(buffer2, offset, 0x400);
            if (num == 0)
            {
                stream3.Close();
                str = encoding.GetString(buffer2, 0, offset);
            }
            else
            {
                offset += num;
                goto Label_02B1;
            }
Label_02E9:
            str2 = "";
            if (mReq.blGetHeaders)
            {
                foreach (string str3 in response.Headers)
                {
                    string str6 = str2;
                    str2 = str6 + str3 + ":" + response.Headers[str3] + "\r\n";
                }
            }
            str = str2 + str;
            request.Abort();
            response.Close();
            return(str);
        }