我有一个XML文件的URL,有没有可能获得它的创建日期?
答案 0 :(得分:1)
你可以这样做
Uri myUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
DateTime today = DateTime.Now;
// Uses the LastModified property to compare with today's date.
if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 0)
Console.WriteLine("\nThe requested URI entity was modified today");
else
if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 1)
Console.WriteLine("\nThe requested URI was last modified on:{0}",
myHttpWebResponse.LastModified);
// Releases the resources of the response.
myHttpWebResponse.Close();
答案 1 :(得分:0)
NO。
因为它是一个网址,你可能无法获得更多关于网络服务器暴露的信息
答案 2 :(得分:0)
是可以使用CURL
curl_getinfo获取文件信息,而无需返回整个正文
实施例
$curl = curl_init('URL_TO_XML');
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);
if ($result === false) {
die (curl_error($curl));
}
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1) {
echo date("Y-m-d H:i:s", $timestamp);
}