我真的陷入了困境,需要专家的帮助。让我解释一下我在尝试实现的目标和设置。我有一个使用Zend_Http_Client在https表单上发布的脚本。在服务器设置上我有tor&私密的跑步。一切都运行良好,但现在我需要通过运行tor&的多个实例来使代码更具可扩展性。 privoxy在同一台服务器上。
因此,我将适用于Zend的Adapter从 Zend_Http_Client_Adapter_Curl 转移到 Zend_Http_Client_Adapter_Proxy 。但在更改适配器后,我遇到了一个奇怪的错误,上面写着 - 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 Framework中完成,因此很难共享所有类和模型,但我正在共享代码的主要部分,它们负责这个 -
$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,它不会让请求退出服务器。
萨钦
答案 0 :(得分:0)
看起来您可能需要用引号包装用户代理。设置标题时请尝试此操作,看看是否能解决问题。
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => "'".self::getRandomUserAgent()."'"
);
$this->setHeaders($headers);
答案 1 :(得分:0)
最后我决定使用原生的cURL库和随附的cookieJar。它像预期的那样工作。
干杯, 萨钦