我真的停留在这,并需要专家的帮助。让我解释我想要达到的目标和设置。我有一个使用Zend_Http_Client在https表单上发布的脚本。在服务器设置上,我运行了& privoxy。一切工作正常,但现在我需要通过在同一台服务器上运行多个privoxy实例来使代码更具可扩展性。Privoxy,Tor和cURL使用Zend HTTP
因此,我从Zend_Http_Client_Adapter_Curl到Zend_Http_Client_Adapter_Proxy偏移为Zend的适配器。但改变适配器后,我已经碰到了一个奇怪的错误,说 - 从客户收到400无效的标题,当我倾倒的Zend客户端的对象,我看到下面的 -
MyWebClientResponse::__set_state(array(
'json' => NULL,
'version' => '1.1',
'code' => 400,
'message' => 'Invalid header received from client',
'headers' =>
array (
'Proxy-agent' => 'Privoxy 3.0.19',
'Content-type' => 'text/plain',
'Connection' => 'close',
),
'body' => 'Invalid header received from client.
',
))
我不明白是什么是我做错了。该代码是在Yii框架这样做很难分享的所有类和模型,但我共享代码的主要部分,这是负责这一点 -
$client = MyWebClient::factory();
$adapter = $client->getAdapter();
$adapter->setConfig(array('timeout' => 120,
'proxy_host' => 'localhost',
'proxy_port' => 8124
));
$client->setAdapter($adapter);
$client->setCookieJar(true);
$client->setParameterPost(array(
'name' => 'firstname',
'password' => 'password,
'login' => 'home'
));
$response = $client->setUri('https://www.domain.com/post.php')->requestApi('POST', false);
这里的类MyWebClient的构造,以防万一它需要,所有其他方法都是标准的。
static public function factory($new = false)
{
if (!isset(self::$client))
{
self::$client = new MyWebClient();
self::$client->setConfig(array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
// 'proxy_host' => 'localhost',
// 'proxy_port' => 8118,
'persistent' => false,
'timeout' => 120
));
}
return self::$client;
}
标题是在requestAPI方法的设置和片段是 -
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => self::getRandomUserAgent()
);
$this->setHeaders($headers);
我非常感谢帮助在此方面。认为它是privoxy不会让请求离开服务器。
Sachin
感谢,但似乎像Zend库正在这样做了。因为当我引用字符串标题转储显示字符串像'\'Mozilla/5.0 ... \''。不知道什么是缺失:( – 2012-08-08 02:53:10