6.6. Making HTTP POST, PUT, and DELETE Requests

Performing HTTP POST, PUT, and DELETE requests are facilitated in Zend_HttpClient by three methods: post(), put(), and delete(), respectively. The post() and put() methods each take a single string parameter, $data, into which should be placed a string with the data properly encoded, as in the following: name=value&foo=bar. The delete() method has no parameters.

Example 6.5. Sending POST data with Zend_HttpClient

<?php
require_once 'Zend/HttpClient.php';

// Instantiate our client object
$http = new Zend_HttpClient();

// Set the URI to a POST data processor
$http->setUri('http://example.org/post/processor');

// Save specific GET variables as HTTP POST data
$postData = 'foo=' . urlencode($_GET['foo']) . '&bar=' . urlencode($_GET['bar']);

// Make the HTTP POST request and save the HTTP response
$httpResponse = $http->post($postData);
?>   

Making a PUT request is the same as in the example above for making a POST request; just substitute the put() method for post().