コード例 #1
0
ファイル: Methods.cs プロジェクト: gilmartmd/sicadv3
        public static String RequisicaoHTTPBkp(string parametros)
        {
            string result = string.Empty;
            bool homologacao = false;

            try
            {
                WS.srvParametros srvParametros = new WS.srvParametros();

                System.Net.HttpWebRequest req;

                if (!homologacao)
                {
                    req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(srvParametros.ConectorSIDSapiens());
                }
                else
                {
                    req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(srvParametros.ConectorSIDSapiensHomologacao());
                }

                req.Method = "POST";

                //req.Proxy = Proxy();
                req.ContentLength = parametros.Length;
                req.ContentType = "application/x-www-form-urlencoded";
                System.IO.StreamWriter stOut = new System.IO.StreamWriter(req.GetRequestStream(), System.Text.Encoding.GetEncoding("ISO-8859-1"));
                stOut.Write(parametros);
                stOut.Close();

                System.IO.StreamReader stIn = new System.IO.StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.GetEncoding("ISO-8859-1"));
                result = stIn.ReadToEnd();
                stIn.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return result;
        }
コード例 #2
0
ファイル: Methods.cs プロジェクト: gilmartmd/sicadv3
        public static String RequisicaoHTTP(string parametros, bool proxy, bool homologacao = false)
        {
            string result = string.Empty;

            try
            {
                WS.srvParametros srvParametros = new WS.srvParametros();

                System.Net.HttpWebRequest request;

                //string conection = srvParametros.ConectorSIDSapiens() + parametros;
                string conection = srvParametros.ConectorSIDSapiensHomologacao() + parametros;

                if (!homologacao)
                {
                    request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(srvParametros.ConectorSIDSapiens() + parametros);
                }
                else
                {
                    request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(srvParametros.ConectorSIDSapiensHomologacao() + parametros);
                }

                //if (proxy)
                //{
                //    request.Proxy = Proxy();
                //}

                // Set some reasonable limits on resources used by this request
                request.MaximumAutomaticRedirections = 4;
                request.MaximumResponseHeadersLength = 4;
                request.Timeout = 2000000;
                // Set credentials to use for this request.
                request.Credentials = CredentialCache.DefaultCredentials;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Get the stream associated with the response.
                Stream receiveStream = response.GetResponseStream();

                // Pipes the stream to a higher level stream reader with the required encoding format.
                StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

                result = readStream.ReadToEnd();

                response.Close();
                readStream.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return result;
        }