0

The Zend_Http_Client docs are confusing and hard to understand. Currently I am using the following code to GET information from the Challonge API:

$client = new Zend_Http_Client("https://api.challonge.com/v1/tournaments/$bracket.json");
$client->setParameterGet(array(
    'api_key' => $apikey,
    'include_participants' => 1,
));
$feed = $client->request()->getBody();

Very simple, three lines. Now this is a GET. How would I do the same exact thing as a PUT? Passing parameters and everything. What about a DELETE?

Jason Axelrod
  • 7,155
  • 10
  • 50
  • 78

2 Answers2

3

Sorry, I know this is not directly related to the question Json Axelrod asked, but I had a similar problem and could not find the solution anywhere online.

I was trying to do a PUT / DELETE request with Magentos Varien_Http_Client

class Varien_Http_Client extends Zend_Http_Client

So I thought the same would apply that was written in this topic and here. However no matter what I tried I could not get PUT nor DELETE requests to work.

Really simple solution in that case: Use Zend_Http_Client instead of Varien_Http_Client. It seems that Magentos Http Client class is adding some extra "convenient" methods for preparing the body that won't allow PUT nor DELETE requests.

MrSnoozles
  • 860
  • 8
  • 13
0

You would do

$client->request('POST')

or

$client->request('DELETE')
Jerome Anthony
  • 7,823
  • 2
  • 40
  • 31
  • Ah... so its as simple as adding a parameter inside of the request? And it defaults to GET, which is why I never needed it before? What about `setParameterGet`? Would I replace that with `setParameterPut`? Or is there a different way to do it? – Jason Axelrod Apr 28 '15 at 06:40
  • It would be setParameterPost for POST – Jerome Anthony Apr 28 '15 at 06:41
  • The API says it has to be a PUT, not POST... are they interchangeable? – Jason Axelrod Apr 28 '15 at 06:42
  • 1
    You have to set raw data. http://framework.zend.com/apidoc/1.7/Zend_Http/Client/Zend_Http_Client.html#setRawData. It has only convenience methods for GET and POST – Jerome Anthony Apr 28 '15 at 06:46