http.server事件
http.server方法
http.server属性
用于处理服务端响应客户端的http通讯模型。
http.ServerResponse事件
http.ServerResponse方法
http.ServerResponse属性
服务端与客户端收到的http请求或响应的解析对象,通常它们也被称为“消息”。
http.IncomingMessage事件
http.IncomingMessage方法
http.IncomingMessage属性
Agent方法
new Agent([options]):如果需要配置代理的设置,需要自定义一个,因为http.request()使用默认的http.globalAgent 具有所有这些值且被设置为各自的默认值。通过new Agent([options])创建一个自定义的代理,options为自定义配置,可配置的选项有:
keepAlive:<boolean>当属性值为true时(默认false)即使没有未完成的请求,也要保持套字节,被用于将来的请求而无需重新建立 TCP 连接。注意不要与http请求头connection的keep-alive值混洗,connection为keep-alive是配置http前请求为长连接的。Connection: keep-alive 请求头始终在使用代理时发送,除非明确指定 Connection 请求头、或者 keepAlive 和 maxSockets 选项分别设置为 false 和 Infinity,在这种情况下将会使用 Connection: close。 默认值: false。
keepAliveMsecs:<number>当使用keepAlive选项时,指定保持套字节的延迟时间,默认为1000。若keepAlive选项配置为false或undefined时,则忽略keepAliveMsecs选项。
maxSockets:<number>每个主机允许套字节的最大数量。默认值为Infinity,即无穷不限制。
maxFreeSockets:<number>在空闲状态下保持打开的套字节的最大数量。该配置也需要是在keepAlive选项配置为true时生效。默认值为256。
timeout:<number>配置套字节的超时时间,在套字节被连接之后设置该超时时间。
1 //自定义http.Agent实例 2 const http = require(‘http‘); 3 const keepAliveAgent = new http.Agent({ keepAlive: true }); 4 options.agent = keepAliveAgent; 5 http.request(options, onResponseCallback);
Agent属性
request事件
request方法
request属性
这里我会在读完node官方文档之后来添加一些内容,可能需要一些时间。
response
原文:https://www.cnblogs.com/ZheOneAndOnly/p/11944882.html