Example #1
0
<?php

require_once 'common.php';
?>
<h2>Requesting HTML Format Data</h2>
<?php 
$uri = $_GET['uri'];
// get default curl handle
$curl = get_curl_handle($uri);
// set other things here
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: text/html"));
echo_info("Requesting HTML by passing 'Accept: text/html' header.");
$response = run_curl_request($curl);
// we either got a 303 redirect or we got a 200 or something else!
$iFrameUri = false;
$requestRdf = false;
if ($response->info['http_code'] == 303) {
    echo_ok("Recieved 303 Redirect HTTP code.");
    echo_ok("Redirect to URI: <a target=\"_new\" href=\"" . $response->info['redirect_url'] . "\">" . $response->info['redirect_url'] . "</a>");
    $iFrameUri = $response->info['redirect_url'];
    $requestRdf = true;
} elseif ($response->info['http_code'] == 302) {
    echo_warning("Recieved 302 Redirect HTTP code. This should be a 303 as we are assuming support for HTTP1.1 ~ 302 is so last century :)");
    echo_ok("Redirect to URI: <a target=\"_new\" href=\"" . $response->info['redirect_url'] . "\">" . $response->info['redirect_url'] . "</a>");
    $iFrameUri = $response->info['redirect_url'];
    $requestRdf = true;
} elseif ($response->info['http_code'] == 200) {
    echo_ok("Recieved 200 OK HTTP code.");
    $iFrameUri = $uri;
} elseif ($response->info['http_code'] == 404) {
    echo_error("Got HTTP response code of 404 Not Found.");
Example #2
0
 private function fetch_rdf_data(&$template)
 {
     $template['log'] .= "\nRequesting RDF by passing 'Accept: application/rdf+xml' header.\n";
     $template['log'] .= "Calling: " . $this->uri . ".\n";
     $curl = get_curl_handle($this->uri);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/rdf+xml"));
     $response = run_curl_request($curl);
     //var_dump($response);
     $response_code = $response->info['http_code'];
     $template['log'] .= "Response code: {$response_code} .\n";
     if ($response_code == 200) {
         $template['rdf_raw'] = $response->body;
         return;
     }
     // follow the redirect to get the data
     if ($response_code == 303 || $response_code == 302) {
         $template['log'] .= "Calling: " . $response->info['redirect_url'] . ".\n";
         $curl = get_curl_handle($response->info['redirect_url']);
         curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/rdf+xml"));
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         // extra redirects for Paris!
         $response = run_curl_request($curl);
         //var_dump($response);
         if ($response->info['http_code'] == 200) {
             $template['log'] .= "Response code: 200.\n";
             $template['rdf_raw'] = $response->body;
             return;
         }
     }
     // not recognised the response code
     $template['log'] .= "Failed to get RDF for uri.\n";
 }