コード例 #1
0
        private void SendGrapevineSMS(string PagerNumber, string PagerMessage, string Reference)
        {
            PagerMessage += " (" + Strings.FormatDateTime(DateAndTime.Now, Constants.vbShortTime) + ")";
            try
            {
                string dt      = Strings.Format(DateAndTime.Now, "yyyy-mm-ddTHH:mm:ss");
                string xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<gviSmsMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<originator>" + My.MySettingsProperty.Settings.GrapeVineAffiliate + "</originator>" + "<affiliateCode>" + My.MySettingsProperty.Settings.GrapeVineAffiliate + "</affiliateCode>" + "<authenticationCode>" + My.MySettingsProperty.Settings.GrapeVineAuthentication + "</authenticationCode>" + "<submitDateTime>" + dt + "</submitDateTime>" + "<messageType>Text</messageType>" + "<recipientList>" + "<message>" + PagerMessage + "</message>" + "<recipient>" + "<msisdn>" + PagerNumber + "</msisdn>" + "<customData>" + "<myRef>" + Reference + "</myRef>" + "</customData>" + "</recipient>" + "</recipientList>" + "</gviSmsMessage>";

                HttpWebRequest  HttpWReq;
                HttpWebResponse HttpWResp;
                byte[]          bytes;
                bytes = Encoding.ASCII.GetBytes(xmlText);
                string GUrl = My.MySettingsProperty.Settings.GrapeVineUrl.ToString();
                HttpWReq               = (HttpWebRequest)WebRequest.Create(GUrl);
                HttpWReq.Method        = "POST";
                HttpWReq.ContentType   = "application/x-www-form-urlencoded";
                HttpWReq.ContentLength = bytes.Length;
                var myWriter = new StreamWriter(HttpWReq.GetRequestStream());
                myWriter.Write(xmlText);
                myWriter.Close();
                HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
                var    myreader  = new StreamReader(HttpWResp.GetResponseStream());
                string Retstring = myreader.ReadToEnd();
                myreader.Close();
                HttpWResp.Close();
            }
            catch (Exception ex)
            {
                logger.Error("sendgrapevinesms" + ex.ToString() + " " + PagerNumber + " " + Reference);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: legrandnarbonne/Chronoid
        public static string getServiceResult(string serviceUrl, string method)
        {
            log("Requesting :" + serviceUrl, _appPath);
            try
            {
                HttpWebRequest  HttpWReq;
                HttpWebResponse HttpWResp;
                HttpWReq = (HttpWebRequest)WebRequest.Create(serviceUrl);

                CredentialCache cc = new CredentialCache();


                HttpWReq.Credentials = CredentialCache.DefaultCredentials;

                if (!string.IsNullOrEmpty(config.User))
                {
                    HttpWReq.Credentials = BuildCredentials(serviceUrl, config.User, config.Password, "NTLM");
                    log(config.LastErreur, _appPath);
                }

                HttpWReq.Method        = string.IsNullOrEmpty(method)? "Post":method;
                HttpWReq.ContentLength = 0;



                HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();

                if (HttpWResp.StatusCode == HttpStatusCode.OK)
                {
                    //Consume webservice with basic XML reading, assumes it returns (one) string
                    XmlReader reader = XmlReader.Create(HttpWResp.GetResponseStream());
                    while (reader.Read())
                    {
                        reader.MoveToFirstAttribute();
                        if (reader.NodeType == XmlNodeType.Text)
                        {
                            return(reader.Value);
                        }
                    }
                    return(string.Empty);
                }
                else
                {
                    log("Getting response :" + HttpWResp.StatusCode.ToString(), _appPath);
                    throw new Exception("Error on remote : " + HttpWResp.StatusCode.ToString());
                }
            }
            catch (Exception e)
            {
                log("Erreur :" + e.ToString(), _appPath);
                return(null);
            }
        }
コード例 #3
0
    private string GetServiceResult(string serviceUrl)
    {
        HttpWebRequest  HttpWReq;
        HttpWebResponse HttpWResp;

        HttpWReq             = (HttpWebRequest)WebRequest.Create(serviceUrl);
        HttpWReq.Method      = "GET";
        HttpWReq.ContentType = "application/json; charset:utf-8";

        HttpWReq.CookieContainer = new CookieContainer();
        if (Request.Cookies != null)
        {
            for (int i = 0; i < Request.Cookies.Count; i++)
            {
                HttpCookie oCookie = Request.Cookies.Get(i);
                Cookie     oC      = new Cookie()
                {
                    Domain  = HttpWReq.RequestUri.Host,
                    Expires = oCookie.Expires,
                    Name    = oCookie.Name,
                    Path    = oCookie.Path,
                    Secure  = oCookie.Secure,
                    Value   = oCookie.Value
                };

                HttpWReq.CookieContainer.Add(oC);
            }
        }

        //using (var writer = new StreamWriter(HttpWReq.GetRequestStream()))
        //{
        //    writer.Write(data);
        //    writer.Flush();
        //    writer.Close();
        //}

        HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
        if (HttpWResp.StatusCode == HttpStatusCode.OK)
        {
            //Consume webservice with basic XML reading, assumes it returns (one) string
            StreamReader reader = new StreamReader(HttpWResp.GetResponseStream());
            return(reader.ReadToEnd());
        }
        else
        {
            throw new Exception("Error: " + HttpWResp.StatusCode.ToString());
        }
    }
コード例 #4
0
        public static string getServiceResult(string serviceUrl)
        {
            HttpWebRequest  HttpWReq;
            HttpWebResponse HttpWResp;

            HttpWReq        = (HttpWebRequest)WebRequest.Create(serviceUrl);
            HttpWReq.Method = "GET";
            HttpWResp       = (HttpWebResponse)HttpWReq.GetResponse();
            if (HttpWResp.StatusCode == HttpStatusCode.OK)
            {
                using (var reader = new StreamReader(HttpWResp.GetResponseStream()))
                    return(reader.ReadToEnd());
            }

            else
            {
                throw new ApplicationException("WebServices.getServiceResult error: " + HttpWResp.StatusCode.ToString());
            }
        }
コード例 #5
0
ファイル: Http.cs プロジェクト: yarivat/Admin
        public static string CallWebService(string webServiceUrl, string header = "")
        {
            HttpWebRequest  HttpWReq;
            HttpWebResponse HttpWResp;

            HttpWReq        = (HttpWebRequest)WebRequest.Create(webServiceUrl);
            HttpWReq.Method = "GET";
            if (header != "")
            {
                HttpWReq.Headers.Add(header);
            }
            HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
            if (HttpWResp.StatusCode == HttpStatusCode.OK)
            {
                //Consume webservice with basic XML reading, assumes it returns (one) string
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ProhibitDtd = false;
                XmlReader reader = XmlReader.Create(HttpWResp.GetResponseStream(), settings);

                try
                {
                    while (reader.Read())
                    {
                        reader.MoveToFirstAttribute();
                        if (reader.NodeType == XmlNodeType.Text)
                        {
                            return(reader.Value);
                        }
                    }
                }
                catch (Exception exception)
                {
                    return(exception.Message);
                }
                return(String.Empty);
            }
            else
            {
                throw new Exception("Error on remote IP to Country service: " + HttpWResp.StatusCode.ToString());
            }
        }
コード例 #6
0
 public string getServiceResult(string serviceUrl)
 {
     try
     {
         HttpWebRequest  HttpWReq;
         HttpWebResponse HttpWResp;
         HttpWReq        = (HttpWebRequest)WebRequest.Create(serviceUrl);
         HttpWReq.Method = "GET";
         HttpWResp       = (HttpWebResponse)HttpWReq.GetResponse();
         if (HttpWResp.StatusCode == HttpStatusCode.OK)
         {
             StreamReader reader = new StreamReader(HttpWResp.GetResponseStream());
             return(reader.ReadToEnd());
         }
         else
         {
             throw new Exception("Error on remote IP to Country service: " + HttpWResp.StatusCode.ToString());
         }
     }
     catch { return("Error"); }
 }
コード例 #7
0
    // this function will make a webservice call to iFolder Admin
    static void WebCallMethod(string MethodName)
    {
        HttpWebRequest  HttpWReq;
        HttpWebResponse HttpWResp = null;

        Configuration SimiasConfig = new Configuration(SimiasDataPath, true);

        string ServerAddress = SimiasConfig.Get(ServerSection, PublicIPKey);

        if (ServerAddress == null)
        {
            tw.WriteLine("iFolder {0}- Failed to get the iFolder server address from config file.", DateTime.Now.ToString());
            return;
        }
        try
        {
            string req = ServerAddress + Path.AltDirectorySeparatorChar + "iFolderAdmin.asmx" + Path.AltDirectorySeparatorChar;

            req += (MethodName + "?");

            StringBuilder Request = new StringBuilder(req);
            ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

            HttpWReq = (HttpWebRequest)WebRequest.Create(Request.ToString());
            HttpWReq.Headers.Add("SOAPAction", MethodName);
            HttpWReq.Method = "GET";
            HttpWResp       = (HttpWebResponse)HttpWReq.GetResponse();
            if (HttpWResp.StatusCode != HttpStatusCode.OK)
            {
                tw.WriteLine("iFolder {0}- WebRequest Failed with status not OK. ", DateTime.Now.ToString());
            }
        }
        catch
        {
            //tw.WriteLine("iFolder {0}- WebRequest Failed with Exception: {1} ",DateTime.Now.ToString(), ex.Message);
            throw;
        }
    }
コード例 #8
0
        /// <summary>
        /// Retrieves remote http contents
        /// </summary>
        /// <param Name="url">Url to the source</param>
        /// <param Name="accessCredentials">optional Credentials</param>
        /// <param Name="proxyUrl">option proxy Url</param>
        /// <returns></returns>
        public static string HttpGetContents(string url, NetworkCredential accessCredentials, string proxyUrl)
        {
            if (!(WebRequest.Create(url) is HttpWebRequest HttpWReq))
            {
                return(null);
            }

            if (accessCredentials != null)
            {
                HttpWReq.Credentials = accessCredentials;
            }
            else
            {
                HttpWReq.Credentials = CredentialCache.DefaultCredentials;
            }

            if (!string.IsNullOrEmpty(proxyUrl))
            {
                HttpWReq.Proxy = new WebProxy(proxyUrl, true);

                if (accessCredentials != null)
                {
                    HttpWReq.Proxy.Credentials = accessCredentials;
                }
                else
                {
                    HttpWReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
                }
            }

            HttpWReq.Timeout         = 20000 * 60;
            HttpWReq.Accept          = "*/*";
            HttpWReq.KeepAlive       = false;
            HttpWReq.CookieContainer = new CookieContainer();

            HttpWebResponse HttpWResp = null;

            try
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate
                {
                    return(true);
                };

                HttpWResp = HttpWReq.GetResponse() as HttpWebResponse;
                Stream receiveStream = HttpWResp.GetResponseStream();
                if (receiveStream == null)
                {
                    return(null);
                }
                using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
                {
                    return(readStream.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (HttpWResp != null)
                {
                    HttpWResp.Close();
                }
            }
        }