Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (75 sloc) 2.204 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php
    /**
* No RDF, just test EasyRdf_Http_Client
*
* This example does nothing but test EasyRdf's build in HTTP client.
* It demonstrates setting Accept headers and displays the response
* headers and body.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/

    set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
    require_once "EasyRdf.php";
    require_once "html_tag_helpers.php";

    $accept_options = array(
      'text/html' => 'text/html',
      'application/rdf+xml' => 'application/rdf+xml',
      'application/xhtml+xml' => 'application/xhtml+xml',
      'application/json' => 'application/json',
      'text/turtle' => 'text/turtle',
    );
?>
<html>
<head>
<title>Test EasyRdf_HTTP_Client Get</title>
<style type="text/css">
.body
{
width: 800px;
font-family: monospace;
font-size: 0.8em;
}
</style>
</head>
<body>
<h1>Test EasyRdf_HTTP_Client Get</h1>
<?= form_tag() ?>
<?= text_field_tag('uri', 'http://tomheath.com/id/me', array('size'=>50)) ?><br />
<?= label_tag('accept', 'Accept Header: ').select_tag('accept',$accept_options) ?>
<?= submit_tag() ?>
<?= form_end_tag() ?>

<?php
    if (isset($_REQUEST['uri'])) {
        $client = new EasyRdf_Http_Client($_REQUEST['uri']);
        $client->setHeaders('Accept',$_REQUEST['accept']);
        $response = $client->request();

?>

<p class="status">
<b>Status</b>: <?= $response->getStatus() ?><br />
<b>Message</b>: <?= $response->getMessage() ?><br />
<b>Version</b>: HTTP/<?= $response->getVersion() ?><br />
</p>

<p class="headers">
<?php
        foreach ($response->getHeaders() as $name => $value) {
            echo "<b>$name</b>: $value<br />\n";
        }
    ?>
</p>

<p class="body">
<?php
        if (defined('ENT_SUBSTITUTE')) {
            // This is needed for PHP 5.4+
            print nl2br(htmlentities($response->getBody(), ENT_SUBSTITUTE | ENT_QUOTES));
        } else {
            print nl2br(htmlentities($response->getBody()));
        }
      ?>
</p>

<?php
    }
?>

</body>
</html>
Something went wrong with that request. Please try again.