Fix comments. Work on sample scripts.
This commit is contained in:
parent
4d0fee6dc9
commit
bb44b27787
|
|
@ -168,12 +168,11 @@ class Response {
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the response to the client. This function also terminates the
|
* Output the response to the client.
|
||||||
* script to prevent and additional output from contaminating the response.
|
|
||||||
*
|
*
|
||||||
* @param bool $headersOnly Do not include the body, only the headers.
|
* @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.
|
// Output the HTTP status code.
|
||||||
header($this->getStatusLine($this->statusCode));
|
header($this->getStatusLine($this->statusCode));
|
||||||
|
|
|
||||||
|
|
@ -13,23 +13,19 @@
|
||||||
require_once('../Request.inc.php');
|
require_once('../Request.inc.php');
|
||||||
require_once('../Response.inc.php');
|
require_once('../Response.inc.php');
|
||||||
|
|
||||||
// Get a Request instance describing the request made to this script.
|
// Make a custom request to talk to the server.
|
||||||
$thisRequest = \wellrested\Request::getRequest();
|
|
||||||
|
|
||||||
// Create a new empty request.
|
|
||||||
$rqst = new \wellrested\Request();
|
$rqst = new \wellrested\Request();
|
||||||
$rqst->hostname = $thisRequest->hostname;
|
|
||||||
$rqst->path = '/wellrested/samples/client-side-endpoint.php';
|
|
||||||
|
|
||||||
// Uncomment this to get a cURL exception.
|
// Use the client-site-endpoint.php script
|
||||||
//$rqst->uri = 'http://not-a-real.domain';
|
$rqst->hostname = $_SERVER['HTTP_HOST'];
|
||||||
|
$rqst->path = '/wellrested/samples/client-side-endpoint.php';
|
||||||
|
|
||||||
// Issue the request, and read the response returned by the server.
|
// Issue the request, and read the response returned by the server.
|
||||||
try {
|
try {
|
||||||
$resp = $rqst->request();
|
$resp = $rqst->request();
|
||||||
} catch (\wellrested\exceptions\CurlException $e) {
|
} 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 = new \wellrested\Response();
|
||||||
$myResponse->statusCode = 500;
|
$myResponse->statusCode = 500;
|
||||||
$myResponse->setHeader('Content-Type', 'text/plain');
|
$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