时间:2021-05-28
复制代码 代码如下:
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);
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了C++实现ping程序的方法。分享给大家供大家参考。具体实现方法如下:该实例涉及ICMP数据包的发送与回显,PING程序代码如下:复制代码代码如下
本文实例讲述了php实现的ping端口函数。分享给大家供大家参考。具体实现代码如下:复制代码代码如下:域名/IP:端口:希望本文所述对大家的PHP程序设计有所帮
使用php模拟我们常用的DOS命令ping命令的方法,这里主要用到的是php的内置函数exec来调用系统的ping命令,从而实现ping命令功能的。复制代码代码
本文实例讲述了asp.net实现简单分页的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下://////分页内容//////页面大小///页面数量
本文实例展示了asp.net截屏功能实现截取web页面的方法,代码简洁易懂,分享给大家供大家参考。具体实现代码如下:usingSystem.Drawing;//