Beispiel #1
0
        public static string Send(string Url, string Message)
        {
            Log.Write("Connect to FinTS Server");
            Log.Write("Url: " + Url);

            if (Trace.Enabled)
            {
                Trace.Write(Message);
            }

            try
            {
                var req = WebRequest.Create(Url) as HttpWebRequest;

                byte[] data = Encoding.ASCII.GetBytes(Helper.EncodeTo64(Message));

                req.Method        = "POST";
                req.Timeout       = 10000;
                req.ContentType   = "application/octet-stream";
                req.ContentLength = data.Length;
                req.KeepAlive     = false;

                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(data, 0, data.Length);
                    reqStream.Flush();
                }

                string FinTSMessage = string.Empty;

                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    using (Stream resStream = res.GetResponseStream())
                    {
                        using (StreamReader streamReader = new StreamReader(resStream, Encoding.UTF8))
                        {
                            FinTSMessage = Helper.DecodeFrom64(streamReader.ReadToEnd());
                        }
                    }
                }

                if (Trace.Enabled)
                {
                    Trace.Write(FinTSMessage);
                }

                return(FinTSMessage);
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());

                return(string.Empty);
            }
        }