从ZEND_HTTP_CLIENT请求中获取PUT或DELETE请求的参数

问题描述:

I want to get params from my PUT or DELETE request sent with Zend_Http_client like this :

$httpClient = new Zend_Http_Client();
$httpClient->setUri("http://mysite/mycontroller/");
$httpClient->setMethod(Zend_Http_Client::PUT);
$data = array("id"=>"1","label"=>"LABEL UPDATE");
$httpClient->setParameterPost($data);
$response = $httpClient->request();

For a POST request I can retrieve params without problems, but for PUT or DELETE I have nothing ... Any idea ? THX

Finally I found this solution : in Zend/Controller/Plugin/ you can find PutHandler.php . It can be used to get PUT params using $this->getRequest()->param_name. Include it in your boostrap.php file with this :

protected function _initRestRoute()
{
    $this->bootstrap('frontController');
    $frontController = Zend_Controller_Front::getInstance();
    $frontController->registerPlugin(new Zend_Controller_Plugin_PutHandler());
    $frontController->registerPlugin(new Zend_Controller_Plugin_DeleteHandler());
    $restRoute = new Zend_Rest_Route($frontController);
    $frontController->getRouter()->addRoute('default', $restRoute);
}

I extended the PutHandler.php script for Delete params and it works.