Ejemplo n.º 1
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request)
        {
            var postData = request.ToPostString();
            var result   = "";

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            webRequest.Method        = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType   = "application/x-www-form-urlencoded";

            // post data is sent as a stream
            StreamWriter myWriter = null;

            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();

            using (StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
                result = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return(result);
        }
Ejemplo n.º 2
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request) {
            
            var postData = request.ToPostString();
            var result = "";

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
            webRequest.Method = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType = "application/x-www-form-urlencoded";

            // post data is sent as a stream
            StreamWriter myWriter = null;
            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();
            using (StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
                result = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return result;
        }
Ejemplo n.º 3
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request)
        {
            var postData = request.ToPostString();
            var result   = new StringBuilder();

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            webRequest.Method = "POST";
            webRequest.Headers["Content-Length"] = postData.Length.ToString();
            webRequest.ContentType = "application/x-www-form-urlencoded";

            /* HACK: No timeout properties are available on WebRequest in .NET Core
             * //set the http connection timeout
             * var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);
             * webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);
             *
             * //set the time out to read/write from stream
             * var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);
             * webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);
             */

            // post data is sent as a stream
            using (StreamWriter myWriter = new StreamWriter(HttpUtility.GetRequestStreamAsync(webRequest).Result))
            {
                myWriter.Write(postData);
            }

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)HttpUtility.GetResponseAsync(webRequest).Result;

            if (response != null)
            {
                var stream = response.GetResponseStream();

                if (stream == null)
                {
                    return(result.ToString());
                }

                using (var responseStream = new StreamReader(stream))
                {
                    while (!responseStream.EndOfStream)
                    {
                        result.Append((char)responseStream.Read());
                        if (result.Length >= MaxResponseLength)
                        {
                            throw new Exception("response is too long.");
                        }
                    }
                }
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return(result.ToString());
        }
Ejemplo n.º 4
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request) {
            
            var postData = request.ToPostString();
            var result = new StringBuilder();

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
            webRequest.Method = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType = "application/x-www-form-urlencoded";

            //set the http connection timeout 
            var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);
            webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);

            //set the time out to read/write from stream
            var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);
            webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);

            // post data is sent as a stream
            StreamWriter myWriter = null;
            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();

            if (response != null)
            {
                var stream = response.GetResponseStream();

                if (stream == null) return result.ToString();

                using (var responseStream = new StreamReader(stream))
                {
                    while (!responseStream.EndOfStream)
                    {
                        result.Append((char)responseStream.Read());
                        if (result.Length >= MaxResponseLength)
                        {
                            throw new Exception("response is too long.");
                        }
                    }

                    responseStream.Close();
                }
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return result.ToString();
        }
Ejemplo n.º 5
0
        public IGatewayResponse Send(IGatewayRequest request, string description)
        {
            var serviceUrl = TEST_URL;

            if (!TestMode)
            {
                serviceUrl = LIVE_URL;
            }

            request.Queue(ApiFields.ApiLogin, ApiLogin);
            request.Queue(ApiFields.TransactionKey, TransactionKey);
            request.Queue(ApiFields.Description, description);
            //validate the inputs
            Validate(request);
            var result   = "";
            var postData = request.ToPostString();

            //override the local cert policy
            ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            webRequest.Method        = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType   = "application/x-www-form-urlencoded";

            // post data is sent as a stream
            StreamWriter myWriter = null;

            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();

            using (StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
                result = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            var response_array = result.Split('|');

            return(DecideResponse(response_array));
        }
Ejemplo n.º 6
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request)
        {
            var postData = request.ToPostString();
            var result   = "";

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            webRequest.Method        = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType   = "application/x-www-form-urlencoded";

            //set the http connection timeout
            var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);

            webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);

            //set the time out to read/write from stream
            var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);

            webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);

            // post data is sent as a stream
            StreamWriter myWriter = null;

            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();

            using (StreamReader responseStream = new StreamReader(response.GetResponseStream())) {
                result = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return(result);
        }
Ejemplo n.º 7
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request)
        {
            string         str1           = request.ToPostString();
            string         str2           = "";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            httpWebRequest.Method        = "POST";
            httpWebRequest.ContentLength = (long)str1.Length;
            httpWebRequest.ContentType   = "application/x-www-form-urlencoded";
            StreamWriter streamWriter = new StreamWriter(((WebRequest)httpWebRequest).GetRequestStream());

            streamWriter.Write(str1);
            streamWriter.Close();
            using (StreamReader streamReader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
            {
                str2 = streamReader.ReadToEnd();
                streamReader.Close();
            }
            return(str2);
        }
Ejemplo n.º 8
0
        protected string SendRequest(string serviceUrl, IGatewayRequest request)
        {
            var postData = request.ToPostString();
            var result   = new StringBuilder();

            //override the local cert policy - this is for Mono ONLY
            //ServicePointManager.CertificatePolicy = new PolicyOverride();

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            var webRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);

            webRequest.Method        = "POST";
            webRequest.ContentLength = postData.Length;
            webRequest.ContentType   = "application/x-www-form-urlencoded";

            //set the http connection timeout
            var httpConnectionTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpConnectionTimeout);

            webRequest.Timeout = (httpConnectionTimeout != 0 ? httpConnectionTimeout : Constants.HttpConnectionDefaultTimeout);

            //set the time out to read/write from stream
            var httpReadWriteTimeout = AuthorizeNet.Environment.getIntProperty(Constants.HttpReadWriteTimeout);

            webRequest.ReadWriteTimeout = (httpReadWriteTimeout != 0 ? httpReadWriteTimeout : Constants.HttpReadWriteDefaultTimeout);

            // post data is sent as a stream
            StreamWriter myWriter = null;

            myWriter = new StreamWriter(webRequest.GetRequestStream());
            myWriter.Write(postData);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            var response = (HttpWebResponse)webRequest.GetResponse();

            if (response != null)
            {
                var stream = response.GetResponseStream();

                if (stream == null)
                {
                    return(result.ToString());
                }

                using (var responseStream = new StreamReader(stream))
                {
                    while (!responseStream.EndOfStream)
                    {
                        result.Append((char)responseStream.Read());
                        if (result.Length >= MaxResponseLength)
                        {
                            throw new Exception("response is too long.");
                        }
                    }

                    responseStream.Close();
                }
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            return(result.ToString());
        }