我有一个XML文件的URL,有可能得到它的创建日期吗?
Yes可以使用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);
}
NO
因为它是一个web url,您可能无法获得web服务器公开的更多信息
你可以这样做
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();
是,如果您有权访问该文件,则可以使用urllib2。
对于蟒蛇2.7,试试这个:
req = urllib2.build_opener()
req.addheaders = [('User-Agent')]
#for full detail use this:
meta = req.open(link).info()
meta =req.open(link).info().getheader("Last-Modified")