• net实现ping的方法


    class ServicePinger
        {
            private static readonly ILog log = LogManager.GetLogger(typeof(ServicePinger));
            public ServicePinger(string siteName, string siteUrl, string serviceUrl)
            {
                if (siteName == null)
                    throw new ArgumentException("siteName can't be null");
    
                if (siteUrl == null)
                    throw new ArgumentException("siteUrl can't be null");
    
                if (serviceUrl == null)
                    throw new ArgumentException("serviceUrl can't be null");
    
                if (siteName.Length == 0)
                    throw new ArgumentException("siteName can't be empty");
    
                if (siteUrl.Length == 0)
                    throw new ArgumentException("siteUrl can't be empty");
    
                if (serviceUrl.Length == 0)
                    throw new ArgumentException("serviceUrl can't be empty");
    
                pingingSiteName = siteName;
                pingingSiteUrl = siteUrl;
                serviceUrlToPing = serviceUrl;
    
    
    
            }
    
            private string pingingSiteName = string.Empty;
            private string pingingSiteUrl = string.Empty;
            private string serviceUrlToPing = string.Empty;
            private int timeoutInMilliseconds = 3000;
    
    
            /// <summary>
            /// Does the actual pinging of the service
            /// </summary>
            public void Ping()
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrlToPing);
                    request.Method = "POST";
                    request.ContentType = "text/xml";
                    request.Timeout = timeoutInMilliseconds;
                    request.Credentials = CredentialCache.DefaultNetworkCredentials;
    
    
                    Stream stream = (Stream)request.GetRequestStream();
                    using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII))
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("methodCall");
                        writer.WriteElementString("methodName", "weblogUpdates.ping");
                        writer.WriteStartElement("params");
                        writer.WriteStartElement("param");
                        writer.WriteElementString("value", pingingSiteName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("param");
                        writer.WriteElementString("value", pingingSiteUrl);
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
    
    
                    request.GetResponse();
                }
                catch (InvalidOperationException ex)
                {
                    log.Error(ex);
                }
                catch (NotSupportedException ex)
                {
                    log.Error(ex);
                }
    
    
    
            }
    
        }
    
  • 相关阅读:
    vue2.0 动画
    I. 对缓存进行处理
    G. 【案例】Ajax实现无刷新分页效果
    H. Ajax对XML信息的接收与处理
    F. 异步同步请求
    D. 接收服务器端返回的信息
    E. 请求GET和POST的不同
    C. 发起对服务器的请求
    B. 创建Ajax对象
    A. AJAX介绍
  • 原文地址:https://www.cnblogs.com/qishiguilai/p/3554753.html
Copyright © 2020-2023  润新知