I'm building an application that makes frequent get calls to an external api and caches the data that is sent back. The api also sends "requestnext" url, last modified date, and ETag that can be used to make conditional get calls for updates. When making a requestnext call, I should be receiving a status 304 when there is no new data, but I'm only getting status 200 (even if there is no new data).
My code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $nextrequest . '&apiKey='.$apikey,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array($lastmod, $etag),
CURLOPT_HEADER => 1,
));
$response = curl_exec($curl);
$curlinfo = curl_getinfo($curl);
// Get http response code
$httpresponse = $curlinfo['http_code'];
The $lastmod and $etag variables contain
$lastmod = If-Modified-Since: Wed, 24 Feb 2016 22:38:22 GMT
$etag = If-None-Match: "ffffffffec3c286a-json"
Any ideas for what I might be doing wrong?
Turns out I was sending the conditional get request to the wrong url. I should've been sending it to the original url I used to make the request (I was sending it to the "nextrequest" url instead).
This was for the AP Elections api in case anyone was wondering!