PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Performing Basic HTTP Requests

Performing simple HTTP requests is very easily done using the request() method, and rarely needs more than three lines of code:

Example 474. Performing a Simple GET Request

<?php
$client 
= new Zend_Http_Client('http://example.org');
$response $client->request();


The request() method takes one optional parameter - the request method. This can be either GET, POST, PUT, HEAD, DELETE, TRACE, OPTIONS or CONNECT as defined by the HTTP protocol [6]. For convenience, these are all defined as class constants: Zend_Http_Client::GET, Zend_Http_Client::POST and so on.

If no method is specified, the method set by the last setMethod() call is used. If setMethod() was never called, the default request method is GET (see the above example).

Example 475. Using Request Methods Other Than GET

<?php
// Preforming a POST request
$response $client->request('POST');

// Yet another way of preforming a POST request
$client->setMethod(Zend_Http_Client::POST);
$response $client->request();


Zend Framework