使用Zend_Http_Client在post请求中传递重复键

时间:2014-09-12 20:57:14

标签: php zend-framework post zend-http-client

我使用POST请求和Zend_Http_Client使用API​​。

我需要查询字符串来模拟看起来像?id=5&id=10&fileName=Sample-Document的get请求。如您所见,有两个id参数。有没有办法使用Zend_Http_Client和$ _POST请求执行此操作?

这是我的代码:

$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');

1 个答案:

答案 0 :(得分:0)

我认为setParameterPost将键作为第一个参数,值作为第二个参数。请参阅源代码:https://github.com/zendframework/zf1/blob/master/library/Zend/Http/Client.php

  

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

但是,要通过多个ID,可以将其作为数组执行。试试这个:

$client->setParameterPost('id[0]', $data['id'][0]);
$client->setParameterPost('id[1]', $data['id'][1]);