目录
Zend_Http_Client
为那些需要执行HTTP请求的程序提供了一个简单的接口.
Zend_Http_Client
可以执行 GET, POST, PUT 和 DELETE 请求.
![]() |
注意 |
---|---|
默认情况下Zend_Http_Client 将追踪 5 次 HTTP 重定向. 要改变这个行为,
可以传入允许重定向的最大数量到get() 的方法
|
例 6.1. 执行一个基本的 GET 请求
<?php require_once 'Zend/Http_Client.php'; try { $http = new Zend_Http_Client('http://example.org'); $response = $http->get(); if ($response->isSuccessful()) { echo $response->getBody(); } else { echo '<p>An error occurred</p>'; } } catch (Zend_Http_Client_Exception $e) { echo '<p>An error occurred (' .$e->getMessage(). ')</p>'; } ?>