通过Zend_Http_Client_Adapter_Curl发布大数据

时间:2012-09-04 01:11:49

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

我使用$site->setParameterPost$site->request('POST')->getBody()将数据发布到某个操作,setParameterPost的一个参数是非常大的数据,并且它不通过post方法发送数据。我该怎么办?

 $config = array('adapter'   => 'Zend_Http_Client_Adapter_Curl' );

 $site = new Zend_Http_Client('http://somewhere.tld/api/news', $config);
 $site->setParameterPost(array(
        'news' => $news, //very big data, without it data send properly
        'modelName' => 'somemodel',
        'method' => 'somemethod',
        'key' => 'something',
        'siteName' => $sitename,
            ));

$sitedata = $site->request('POST')->getBody();

1 个答案:

答案 0 :(得分:1)

我应该使用流媒体请求,只允许使用PUT方法。

$http_client = new Zend_Http_Client ('http://something.some/thing');
$http_client->setConfig (array (
    'adapter' => 'Zend_Http_Client_Adapter_Curl',
    'timeout' => 180
));

$file = fopen ('news.dat', 'r'); // put all your news to the file beforehand
$http_client->setRawData ($file);
$http_client->setParameterPost (array (
    'modelName' => 'somemodel',
    'method' => 'somemethod',
    'key' => 'something',
    'siteName' => $sitename
));
$response = $http_client->request ('PUT');

在服务器端,您可以通过

访问大数据
fopen ("php://input", "r");