1

I'm trying to use the PUT method with the Zend Http Client but I'm unable to add parameters to the request.

Here's my code snippet:

$client = new Zend_Http_Client($this->url);
$client->setAuth($this->username, $this->password, Zend_Http_Client::AUTH_BASIC);
$client->setParameterPut('fruit',$var);
$result = $client->request('PUT');
$data = $result->getBody();

I have already declared "url", "username", "password" and "var" previously in the code.

wpp
  • 7,093
  • 4
  • 33
  • 65
user2509780
  • 121
  • 2
  • 9

1 Answers1

1

While you didn't include the error, there is no such method in Zend_Http_Client as $client->setParameterPut().

PUT requests do not have "parameter" semantics. To send content in a PUT request, you most likely want to use $client->setRawData($data, $enctype) where $data is your data, that is parameters encoded in some form, and $enctype is the Content-type, which is optional but recommended or required by most APIs.

shevron
  • 3,463
  • 2
  • 23
  • 35
  • Isn't setRawData() used for xml/json/zip data? I'm trying to pass a variable whose value is dynamic. – user2509780 Jan 29 '14 at 14:28
  • @user2509780 the data can be anything you want, static or dynamic. If you are passing "parameters", they must be encoded somehow (e.g. url-encoded as used in standard HTML forms), and your server needs to know how to decode them, but as long as that is known the contents can be anything. – shevron Jan 30 '14 at 19:34