net实现ping的方法
程序员文章站
2022-05-29 17:50:25
...
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 ca
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; ////// Does the actual pinging of the service /// 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); } } }
上一篇: C#viewstate
下一篇: 读大数据有感
推荐阅读
-
python实现简单socket程序在两台电脑之间传输消息的方法
-
php实现压缩多个CSS与JS文件的方法,
-
详解Laravel实现supervisor执行异步进程的方法
-
jquery实现Li滚动时滚动条自动添加样式的方法_jquery
-
CI框架AR操作(数组形式)实现插入多条sql数据的方法,ciar
-
C#/.NET/.NET Core定时任务调度的方法或者组件有哪些--Timer,FluentScheduler还是...
-
Node.JS段点续传:Nginx配置文件分段下载功能的实现方法_node.js
-
php实现上传图片保存到数据库的方法_PHP教程
-
yii2中添加验证码的实现方法
-
利用Python脚本生成sitemap.xml的实现方法