Beispiel #1
0
        public string SendRequestPost(string URL, string subject)
        {
            string          strOut        = "";
            HttpWebResponse result        = null;
            HttpWebRequest  req           = null;
            Stream          newStream     = null;
            Stream          ReceiveStream = null;
            StreamReader    sr            = null;

            try
            {
                // Url запрашиваемого методом POST скрипта
                req = (HttpWebRequest)WebRequest.Create(URL);
                req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                req.Method    = "POST";
                req.Timeout   = 60000;
                req.UserAgent = "Zeus ver. " + Ipaybox.CoreVersion + "; " + Ipaybox.Terminal.terminal_id;
                // эта строка необходима только при защите скрипта на сервере Basic авторизацией
                //req.Credentials = new NetworkCredential("login", "password");
                //req.ContentType = "application/x-www-form-urlencoded";
                byte[] SomeBytes = null;
                // передаем список пар параметров / значений для запрашиваемого скрипта методом POST
                // в случае нескольких параметров необходимо использовать символ & для разделения параметров
                // в данном случае используется кодировка windows-1251 для Url кодирования спец. символов значения параметров
                SomeBytes         = Encoding.GetEncoding(1251).GetBytes(HttpUtility.UrlEncode(subject, Encoding.GetEncoding(1251)));
                req.ContentLength = SomeBytes.Length;
                newStream         = req.GetRequestStream();
                newStream.Write(SomeBytes, 0, SomeBytes.Length);
                newStream.Close();
                // считываем результат работы
                result        = (HttpWebResponse)req.GetResponse();
                ReceiveStream = result.GetResponseStream();

                if (result.ContentEncoding.ToLower().Contains("gzip"))
                {
                    ReceiveStream = new GZipStream(ReceiveStream, CompressionMode.Decompress);
                }
                else
                if (result.ContentEncoding.ToLower().Contains("deflate"))
                {
                    ReceiveStream = new DeflateStream(ReceiveStream, CompressionMode.Decompress);
                }

                Encoding encode = Encoding.GetEncoding(1251);
                sr = new StreamReader(ReceiveStream, encode);
                Char[] read  = new Char[256];
                int    count = sr.Read(read, 0, 256);

                while (count > 0)
                {
                    String str = new String(read, 0, count);

                    strOut += str;
                    count   = sr.Read(read, 0, 256);
                }

                return(strOut);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (newStream != null)
                {
                    newStream.Close();
                }
                if (ReceiveStream != null)
                {
                    ReceiveStream.Close();
                }
                if (sr != null)
                {
                    sr.Close();
                }
                if (result != null)
                {
                    result.Close();
                }
            }
        }
Beispiel #2
0
 public void EndFileReceive()
 {
     IsReceivingFile = false;
     ReceiveStream.Close();
     ReceiveStream = null;
 }