0

I'm using an API using a POST request and Zend_Http_Client.

I need the query string to emulate a get request that would look like ?id=5&id=10&fileName=Sample-Document. As you can see, there are two id parameters. Is there a way to do this using Zend_Http_Client and a $_POST request?

This is my code thusfar:

$client = new Zend_Http_Client();
.
..
... $client->config stuff goes here
..
.
$data = array('id'=>array('5', '10')), 'fileName'=>'Sample-Document');

$client->setParameterPost($data['fileName'], 'fileName');

// theoretically, i'd like to do it like this, but it doesn't work since i think the second line overwrites the first
$client->setParameterPost('id', ($data['id'][0]);
$client->setParameterPost('id', $data['id'][1]);
$client->request('POST');
Nolan Knill
  • 499
  • 5
  • 19

1 Answers1

0

I think setParameterPost takes the key as the first argument and the value as the second. See the source code: https://github.com/zendframework/zf1/blob/master/library/Zend/Http/Client.php

public function setParameterPost($name, $value = null)

However to pass multiple IDs through you could do it as an array. Try this:

$client->setParameterPost('id[0]', $data['id'][0]);
$client->setParameterPost('id[1]', $data['id'][1]);
RobbieP
  • 698
  • 4
  • 13
  • The problem is I need to POST the id parameter twice due to some API restraints (who knows why they did this), as if both ids were id [0] – Nolan Knill Sep 12 '14 at 23:13
  • Have you tried `$client->setRawData('id=5&id=10&fileName=Sample-Document', 'application/x-www-form-urlencoded')` ? – RobbieP Sep 12 '14 at 23:30
  • I've tried this, but my only concern is how would I add a file (not just a file name) to this request? I didn't include that part in the question originally, but before the `$client->setParameterPost()` stuff is happening, I'm adding a file by `$client->setFileUpload()`. If I were to do the `$client->setRawData()`, I would lose that file upload on this request. – Nolan Knill Sep 19 '14 at 14:27