Zend Framework 下实现简单的 proxy 功能 - ○白子○ 的Blog

Zend Framework 下实现简单的 proxy 功能

[ 2009-09-13 21:17:45 | Author: seaboat ]
Font Size: Large | Medium | Small
用 Zend_Http_Client 可实现简单的 Proxy 功能,代码如下:
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();
 }
 }
}
用法:
http://domainname/proxy?url=http://....
Comments Feed Comments Feed: http://www6.webng.com/seaboat/feed.asp?q=comment&id=761

There is no comment on this article.

Post Comment
Smilies
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password: