进程:
ClientRequest
实现了Readable Stream接口, 因此是一个类型.
Event: ‘data’
返回:
chunk
缓冲区: 响应体数据块。
data
事件是将响应数据转换为应用程序代码的常用方法。
Event: ‘end’
Event: ‘aborted’
正在进行的 HTTP 事务被取消后触发。
Event: ‘error’
返回:
error
通常保存一个错误字符串,识别失败的根本原因。
当流响应数据事件遇到错误时发出。 例如, 如果服务器在响应仍在流时关闭基础, 则会在响应对象上发出一个 error
事件, 随后将在请求对象上执行 close
事件。
实例属性
response.statusCode
一个指示 HTTP 响应状态代码的 Integer
。
response.statusMessage
表示HTTP状态消息的。
response.headers
A Record<string, string | string[]>
representing the HTTP response headers. The headers
object is formatted as follows:
- 所有的头文件名是小写的。
- Duplicates of
age
,authorization
,content-length
,content-type
,etag
,expires
,from
,host
,if-modified-since
,if-unmodified-since
,last-modified
,location
, ,proxy-authorization
,referer
,retry-after
,server
, oruser-agent
are discarded. set-cookie
is always an array. Duplicates are added to the array.- For duplicate
cookie
headers, the values are joined together with ‘; ‘.
response.httpVersion
表示HTTP协议版本号的 String
。 一般是“1”或“1.1”。 此外 httpVersionMajor
和httpVersionMinor
两整数值可读属性,分别返回HTTP的主要和次要版本号
response.httpVersionMajor
response.httpVersionMinor
表示http协议次要版本号的整数
。