1.1.0 • Published 4 years ago
heom-request v1.1.0
request(url [,callback] [,test])
request(options [,callback] [,test])
- url : \<string> : 如果 url 是一个字符串,则会解析为 options。
- options : \<Object> :
在 http.request 的 options 的基础上有所改进。
- noEnd : \<boolean> : 不调用 request.end()。
- data : \<string> | \<Buffer> : 如果 noEnd 为假,将调用 request.end(data)。
- timeout : \<number> : 默认为 60000,以毫秒为单位。
- callback : \<Function> :
回调函数,当 test 为假时为 (error, response),当 test 为真时为 (error, statusCode)。
- error : \<Error> : 被捕获的错误。
- response : \<http(s).IncomingMessage> :
它可用于访问响应状态、消息头、以及数据。
- data : \<string> : 数据。
- json : \<JSON> : 数据的 JSON,如果数据不是 JSON 的格式,则为 null。
- statusCode : \<number> : 发送到客户端的状态码。
- test : \<boolean> : 测试模式,当收到此请求的响应后即中断。
request.promise(url [,test])
request.promise(options [,test])
- 它们返回 Promise 对象而不是使用回调。
###'timeout' 事件
当 'timeout' 事件触发时,将触发一次 'error' 事件。
###'error' 事件
当 'error' 事件触发时,将调用一次 callback(error, null)。
###'close' 事件
当 'close' 事件触发时,将调用一次 callback(null, response)。