diff --git a/Response.inc.php b/Response.inc.php index 2c98dfa..6e072ab 100644 --- a/Response.inc.php +++ b/Response.inc.php @@ -168,12 +168,11 @@ 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. */ - public function respond($headersOnly = false) { + public function respond($headersOnly=false) { // Output the HTTP status code. header($this->getStatusLine($this->statusCode)); diff --git a/samples/client-side-request-and-response.php b/samples/client-side-request-and-response.php index 160d54d..fe87c51 100644 --- a/samples/client-side-request-and-response.php +++ b/samples/client-side-request-and-response.php @@ -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'); diff --git a/samples/client-side-simple-request.php b/samples/client-side-simple-request.php new file mode 100644 index 0000000..87a24dd --- /dev/null +++ b/samples/client-side-simple-request.php @@ -0,0 +1,27 @@ +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; + +?>