Skip to content
jrbasso edited this page Dec 11, 2010 · 11 revisions

The HttpSocket class has undergone some changes.

Don't change the header keys

Following others places in core, the HttpSocket do not change the helpers. The RFC 2616 says that helpers are case insensitive.

So, if your server send the below header:

HTTP/1.1 200 OK
Date: Mon, 16 Apr 2007 04:14:16 GMT
server: CakeHttp Server
content-tyPe: text/html

You $http->response['header'] will be:

Array(
    'Date' => 'Mon, 16 Apr 2007 04:14:16 GMT',
    'server' => 'CakeHttp Server',
    'content-tyPe' => 'text/html'
)

Returning as reference

The methods get(), post(), put(), delete() and request() now returns the content as reference. It is good when the server response is big. The reference is to $http->response['body']. To use it, you need receive the result with reference, for example:

$response =& $http->get('http://www.cakephp.org');

Getting result using stream (or simply download the result)

HttpSocket have a new method called setContentResource(). Setting a resource with this method the content will be wrote to this resource, using fwrite(). To you download a file, you can do:

$http = new HttpSocket();
$f = fopen('feed.xml', 'w');
$http->setContentResource($f);
$http->get('http://www.example.com/feed.xml');
fclose($f);

Attention: The header is not included in file.

Independent cookie by host

Authentication methods

Now you can create your authentication method to use with HttpSocket.

Support to Proxy

Clone this wiki locally