마지막 수정 된 시간을 얻기 위해 HTTP 요청을 보낼 수 있습니까?

StackOverflow https://stackoverflow.com/questions/1806686

  •  05-07-2019
  •  | 
  •  

문제

파일 자체 대신?

편집하다

PHP의 데모로 가장 좋습니까?

도움이 되었습니까?

해결책

<?php
// Get Headers
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,            'http://example.com/'); 
curl_setopt($ch, CURLOPT_HEADER,         true); 
curl_setopt($ch, CURLOPT_NOBODY,         true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT,        10); 
$response = curl_exec($ch); 

// Process Headers
$headerLines = explode("\r\n", $response);
foreach ($headerLines as $headerLine) {
    $headerLineParts = explode(': ', $headerLine);
    if (count($headerLineParts) >= 2) {
        $headers[$headerLineParts[0]] = $headerLineParts[1];
    }
}

echo $headers['Last-Modified'];
?>

다른 팁

Yes. The "HEAD" method returns only the response headers and not the actual data.

You can use php's get_headers function

$a = get_headers('http://sstatic.net/so/img/logo.png');
print_r($a);

In your HTTP request you should add any of these header attributes, and you may receive an 304 (Last modified)

  1. If-Modified-Since
  2. If-None-Match
  3. If-Unmodified-Since

Andrei is correct, HEAD will only get the headers. My suggestion will return only the header and no body if the condictions are met. If the content has been updated the body will contain the new information.

You need to write some service to handle the http request and extract the last modified date for the requested file and return the date in response.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top