[ZF-10089] Zend_Log
[zend.git] / documentation / manual / zh / module_specs / Zend_Http_Response.xml
blob648422ac285dd123e5ed326de659456d2cd9608f
1 <sect1 id="zend.http.response">
2     <title>Zend_Http_Response</title>
4     <sect2 id="zend.http.response.introduction">
5         <title>简介</title>
6         <para>
7             对于由<xref linkend="zend.http.client" />返回的应答(Response)信息,<code>Zend_Http_Response</code>
8             可以提供简单的访问方式。 它提供一组友好的方法来获得从请求返回的应答信息:
9             <itemizedlist>
10                 <listitem>
11                     <para>
12                         <code>isError()</code>: 如果收到HTTP出错状态的代码,返回TRUE, 否则返回FALSE.
13                     </para>
14                 </listitem>
15                 <listitem>
16                     <para>
17                         <code>isSuccessful()</code>: 如果得到HTTP请求成功的状态代码,返回TRUE, 否则返回FALSE.
18                     </para>
19                 </listitem>
20                 <listitem>
21                     <para>
22                         <code>isRedirect()</code>: 如果得到HTTP重定向的状态代码,返回TRUE, 否则返回FALSE.
23                     </para>
24                 </listitem>
25                 <listitem>
26                     <para>
27                         <code>getStatus()</code>: 返回HTTP请求的状态代码.
28                     </para>
29                 </listitem>
30                 <listitem>
31                     <para>
32                         <code>getHeaders()</code>: 以数组的形式返回HTTP请求头部信息的字符串.
33                     </para>
34                 </listitem>
35                 <listitem>
36                     <para>
37                         <code>getBody()</code>: 返回HTTP正文内容(字符串).
38                     </para>
39                 </listitem>
40             </itemizedlist>
41         </para>
42         <example>
43             <title>处理HTTP应答</title>
44             <programlisting role="php"><![CDATA[<?php
45 require_once 'Zend/Http/Client.php';
46 try {
47     $http = new Zend_Http_Client('http://example.org');
48     $response = $http->get();
49     if ($response->isSuccessful()) {
50         echo $response->getBody();
51     } else {
52         echo "<p>发生错误</p>\n";
53         echo "HTTP Status: " . $response->getStatus() . "\n";
54         echo "HTTP Headers:\n";
55         $responseHeaders = $response->getHeaders();
56         foreach ($responseHeaders as $responseHeaderName => $responseHeaderValue) {
57             echo "$responseHeaderName: $responseHeaderValue\n";
58         }
59     }
60 } catch (Zend_Http_Client_Exception $e) {
61     echo '<p>An error occurred (' .$e->getMessage(). ')</p>';
63 ?>]]></programlisting>
64         </example>
65     </sect2>
66 </sect1>
67 <!--
68 vim:se ts=4 sw=4 et:
69 -->