Die Funktion GetURLDate liefert das aktuelle Datum & Uhrzeit der übergebenen URL.
Beispiel:
DateTime dt = GetURLDate("192.168.0.27");
public static DateTime GetURLDate(string cUrl)
{
string url = cUrl.Trim();
string cHead = string.Empty;
DateTime oDate = DateTime.Now; //.MinValue;
try
{
cHead = "Step1";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "GET";
req.Timeout = 5000;
req.KeepAlive = false;
cHead = "Step2";
WebResponse result = req.GetResponse();
cHead = "Step3";
WebHeaderCollection wH = result.Headers;
cHead = "Step4";
string cItem = "";
for (int i = 0; i < wH.Count; i++)
{
cItem = wH.GetKey(i).ToUpper().Trim();
if (cItem == "DATE")
{
cHead = wH.Get(i);
oDate = DateTime.ParseExact(cHead, "r", null);
break;
}
}
result.Close();
req.Abort();
result = null;
req = null;
}
catch (Exception e)
{
}
return (oDate);
}
Kommentare zum Snippet