compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (11)

View Page History
{zone-data:use-cases}
||UC-01||
Sending a simple GET request quickly and checking the response status:
{code}
$response = \Zend\Http\Client::get('http://example.com/foo/bar');
{code}

||UC-02||
Another method of sending a GET request quickly
Here's another method of sending a GET request quickly:
{code}
$response = \Zend\Http\Transport\Socket::send(new \Zend\Http\Request('http://example.com/foo/bar'));
{code}

||UC-02||
Sending a POST request with some URL-encoded parameters
{code}
$params = array(
'war' => 'peace',
'freedom' => 'slavery',
'banana' => 'apple'
);

$response = \Zend\Http\Client::post('http://example.com/', $params);
{code}

Another method of doing the same thing, this time with more control over the request:
{code}
$request = new \Zend\Http\Request('http://example.com/', 'POST');
$request->setBody(http_build_query($params), 'application/x-form-urlencoded');
$response = $client->send($request);
{code}
{zone-data}

||UC-03||
Adding additional request headers
{code}
$request = new \Zend\Http\Request('http://example.com/', 'POST');
$request->setHeader('From', 'nobody@example.com')
->setHeaders(array(
'Accept' => 'text/xml, text/html, */*',
'Accept-charset' => 'utf8, *;q=0.8',
'Accept-encoding' => 'identity'
));

$response = $client->send($request);
{code}

{zone-data:skeletons}
{code}
class Zend_Magic_Exception extends Zend_Exception {}

class Zend_Magic {
namespace Zend\Http\Message;
...
abstract class MessageAbstract
{
/**
* HTTP version constants
*/
const HTTP_VER_10 = '1.0';
const HTTP_VER_11 = '1.1';

/**
* Message headers
*
* @var array
*/
protected $_headers = array();

/**
* HTTP version
*
* @var string
*/
protected $_httpVersion = self::HTTP_VER_11;

/**
* Set a header
*
* @param string $name
* @param string $value
* @return \Zend\Http\Message\MessageAbstract
*/
public function setHeader($name, $value)
{ }

/**
* Set several headers by passing an associative array
*
* @param array $headers
* @return \Zend\Http\Message\MessageAbstract
*/
public function setHeaders(array $headers)
{ }

/**
* Get the value of the header $name, or null if it does not exist
*
* @param string $name
* @return string | null
*/
public function getHeader($name)
{ }

/**
* Get all headers as an array
*
* @return array
*/
public function getHeaders()
{ }

/**
* Get all headers as a string
*
* @param $eol Optional End Of Line string
* @return string
*/
public function getHeadersAsString($eol = "\r\n")
{ }

/**
* Set the message's HTTP version
*
* @param string $ver
* @return \Zend\Http\Message\MessageAbstract
*/
public function setHttpVersion($ver)
{ }

/**
* Get the message's HTTP version
*
* @return string
*/
public function getHttpVersion()
{ }

/**
* Convert the message to a string
*
* @return string
*/
public function __toString()
{
return $this->_getStartLine() . "\r\n" .
$this->getHeadersAsString() . "\r\n" .
$this->getBody();
}

/**
* Get the message body
*
* @return string
*/
abstract public function getBody();

/**
* Get the message start line - this is message type dependant
*
* @return string
*/
abstract protected function _getStartLine();

/**
* Static helper methods
*/

/**
* Check if the provided string is a valid token
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
* @param string $str
* @return boolean
*/
static protected function _isToken($str)
{ }
}
{code}

{code}
namespace Zend\Http;
use \Zend\Http\Message\MessageAbstract as MessageAbstract;

class Request extends MessageAbstract
{
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
const HEAD = 'HEAD';
const OPTIONS = 'OPTIONS';
const TRACE = 'TRACE';
const CONNECT = 'CONNECT';

protected $_method;

protected $_uri;

protected $_body;

public function __construct($uri, $method = 'GET', array $headers = array(), $body = null)
{ }

public function setUri($uri)
{ }

public function setMethod($method)
{ }

public function setBody($body)
{ }

public function getBody()
{ }

protected function _getStartLine()
{ }
}
{code}

{zone-data}