agent.createConnection(options[, callback])
-
options<Object> 包含连接详细信息的选项。查看net.createConnection()以获取选项的格式¥
options<Object> Options containing connection details. Checknet.createConnection()for the format of the options -
callback<Function> 接收创建的套接字的回调函数¥
callback<Function> Callback function that receives the created socket -
¥Returns: <stream.Duplex>
生成用于 HTTP 请求的套接字/流。
¥Produces a socket/stream to be used for HTTP requests.
默认情况下,此函数与 net.createConnection() 相同。但是,如果需要更大的灵活性,自定义代理可能会覆盖此方法。
¥By default, this function is the same as net.createConnection(). However,
custom agents may override this method in case greater flexibility is desired.
可以通过以下两种方式之一提供套接字/流:通过从此函数返回套接字/流,或将套接字/流传递给 callback。
¥A socket/stream can be supplied in one of two ways: by returning the
socket/stream from this function, or by passing the socket/stream to callback.
此方法保证返回 <net.Socket> 类(<stream.Duplex> 的子类)的实例,除非用户指定 <net.Socket> 以外的套接字类型。
¥This method is guaranteed to return an instance of the <net.Socket> class, a subclass of <stream.Duplex>, unless the user specifies a socket type other than <net.Socket>.
callback 的参数为 (err, stream)。
¥callback has a signature of (err, stream).