Zend Framework 下实现简单的 proxy 功能
[ 2009-09-13 21:17:45 | Author: seaboat ]
用 Zend_Http_Client 可实现简单的 Proxy 功能,代码如下:
http://domainname/proxy?url=http://....
Comments Feed: http://www6.webng.com/seaboat/feed.asp?q=comment&id=761
public function proxyAction()
{
$params = $this->_getAllParams();
if(!isset($params['url'])) {
echo 'URL未指定。';
} else {
$http = new Zend_Http_Client($params['url']);
$response = $http->request();
if ($response->getStatus() == 200) {
header('Content-Type: text/html; charset=utf-8');
echo mb_convert_encoding($response->getBody(), "utf-8", "auto");
} else {
echo 'HTTP通信错误发生。<br />' . $response->getStatus() . ": " . $response->getMessage();
}
}
}
用法:{
$params = $this->_getAllParams();
if(!isset($params['url'])) {
echo 'URL未指定。';
} else {
$http = new Zend_Http_Client($params['url']);
$response = $http->request();
if ($response->getStatus() == 200) {
header('Content-Type: text/html; charset=utf-8');
echo mb_convert_encoding($response->getBody(), "utf-8", "auto");
} else {
echo 'HTTP通信错误发生。<br />' . $response->getStatus() . ": " . $response->getMessage();
}
}
}
http://domainname/proxy?url=http://....
Comments Feed: http://www6.webng.com/seaboat/feed.asp?q=comment&id=761
There is no comment on this article.






