Fix comments. Work on sample scripts.
This commit is contained in:
parent
4d0fee6dc9
commit
bb44b27787
|
|
@ -168,8 +168,7 @@ class Response {
|
|||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Output the response to the client. This function also terminates the
|
||||
* script to prevent and additional output from contaminating the response.
|
||||
* Output the response to the client.
|
||||
*
|
||||
* @param bool $headersOnly Do not include the body, only the headers.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -13,23 +13,19 @@
|
|||
require_once('../Request.inc.php');
|
||||
require_once('../Response.inc.php');
|
||||
|
||||
// Get a Request instance describing the request made to this script.
|
||||
$thisRequest = \wellrested\Request::getRequest();
|
||||
|
||||
// Create a new empty request.
|
||||
// Make a custom request to talk to the server.
|
||||
$rqst = new \wellrested\Request();
|
||||
$rqst->hostname = $thisRequest->hostname;
|
||||
$rqst->path = '/wellrested/samples/client-side-endpoint.php';
|
||||
|
||||
// Uncomment this to get a cURL exception.
|
||||
//$rqst->uri = 'http://not-a-real.domain';
|
||||
// Use the client-site-endpoint.php script
|
||||
$rqst->hostname = $_SERVER['HTTP_HOST'];
|
||||
$rqst->path = '/wellrested/samples/client-side-endpoint.php';
|
||||
|
||||
// Issue the request, and read the response returned by the server.
|
||||
try {
|
||||
$resp = $rqst->request();
|
||||
} catch (\wellrested\exceptions\CurlException $e) {
|
||||
|
||||
// Create new response to send to output to the browser.
|
||||
// Explain the cURL error and provide an error status code.
|
||||
$myResponse = new \wellrested\Response();
|
||||
$myResponse->statusCode = 500;
|
||||
$myResponse->setHeader('Content-Type', 'text/plain');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This script will make a request to google and output the response.
|
||||
*/
|
||||
|
||||
// Include the Well RESTed Request and Response class files.
|
||||
require_once('../Request.inc.php');
|
||||
|
||||
// Make a requst to Google in one line:
|
||||
$rqst = new \wellrested\Request();
|
||||
$rqst->uri = 'https://www.google.com/search?q=my+search+terms';
|
||||
|
||||
// You could also set the members individually, like this:
|
||||
//$rqst->protocol = 'https';
|
||||
//$rqst->hostname = ['www.google.com';
|
||||
//$rqst->path = '/search';
|
||||
//$rqst->query = array('q' => 'my search terms');
|
||||
|
||||
// Make the request and obtain an Response instance.
|
||||
$resp = $rqst->request();
|
||||
|
||||
// Output the response body and exit.
|
||||
print $resp->body;
|
||||
exit;
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue