3

我有一个 XML 文件的 URL,是否有可能获得它的创建日期?

4

3 回答 3

3

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);
} 
于 2012-09-12T09:43:13.490 回答
1

不。
因为它是一个 Web url,所以您可能无法获得 Web 服务器公开的更多信息

于 2012-09-12T09:36:00.893 回答
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(); 
于 2015-10-01T09:27:44.333 回答