Page 85 - Node.js开发指南
P. 85

4.6  参考资料    77


                   2. http.ClientResponse                                                             1
                   http.ClientResponse 与 http.ServerRequest 相似,提供了三个事件 data、end
               和  close,分别在数据到达、传输结束和连接结束时触发,其中  data  事件传递一个参数
               chunk,表示接收到的数据。
                   http.ClientResponse 也提供了一些属性,用于表示请求的结果状态,参见表 4-3。                                  2

                                            表4-3  ClientResponse 的属性
                                 名  称                                      含  义
                               statusCode                        HTTP 状态码,如 200、404、500               3
                               httpVersion                       HTTP 协议版本,通常是 1.0 或 1.1
                               headers                           HTTP 请求头
                               trailers                          HTTP 请求尾(不常见)
                                                                                                      4

                   http.ClientResponse 还提供了以下几个特殊的函数。
                     response.setEncoding([encoding]):设置默认的编码,当  data  事件被触发
                      时,数据将会以 encoding 编码。默认值是 null,即不编码,以 Buffer 的形式存
                                                                                                      5
                      储。常用编码为 utf8。
                     response.pause():暂停接收数据和发送事件,方便实现下载功能。
                     response.resume():从暂停的状态中恢复。
                                                                                                      6
               4.6  参考资料

                     Node.js Manual & Documentation: http://nodejs.org/api/index.html。
                     “Understanding process.nextTick()”: http://howtonode.org/understanding- process-   7
                      next-tick。
                     “揭秘Node.js事件”: http://www.grati.org/?p=318。

                                                                                                      8




                                                                                                      9






                                                                                                      10
   80   81   82   83   84   85   86   87   88   89   90