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


发送一块正文。

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

callback 参数是可选的,将在刷新此数据块时调用,但前提是该块非空。

如果整个数据被成功刷新到内核缓冲区,则返回 true。 如果所有或部分数据在用户内存中排队,则返回 false。 当缓冲区再次空闲时,则将触发 'drain'

当使用空字符串或缓冲区调用 write 函数时,则什么都不做并等待更多输入。

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.