request.write(chunk[, encoding][, callback])

发送请求主体的一个数据块。 通过多次调用该方法,完整的请求主体可被发送到服务器。 当创建请求时,建议使用 ['Transfer-Encoding', 'chunked'] 请求头。

encoding 参数是可选的,仅当 chunk 是字符串时才有效。 默认为 'utf8'

callback 参数是可选的,当数据块被刷新且不为空时调用。

如果完整的数据被成功地刷新到内部缓冲,则返回 true。 如果失败或部分数据还在内存中等待队列,则返回 false。 当缓冲再次可用时触发 'drain' 事件。

当调用 write 函数传入空字符串或空 buffer 时,不会进行任何操作。

Sends a chunk of the body. By calling this method many times, a request body can be sent to a server — in that case it is suggested to use the ['Transfer-Encoding', 'chunked'] header line when creating the request.

The encoding argument is optional and only applies when chunk is a string. Defaults to 'utf8'.

The callback argument is optional and will be called when this chunk of data is flushed, but only if the chunk is non-empty.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory. 'drain' will be emitted when the buffer is free again.

When write function is called with empty string or buffer, it does nothing and waits for more input.