request.write(chunk[, encoding][, callback])
chunk<string> | <Buffer> | <Uint8Array>encoding<string>callback<Function>- 返回:<boolean>
发送一段请求体。此方法可以被多次调用。如果没有设置 Content-Length,数据将会自动使用 HTTP 分块传输编码,这样服务器就知道数据何时结束。会添加 Transfer-Encoding: chunked 头。调用 request.end() 是完成请求发送所必需的。
【Sends a chunk of the body. This method can be called multiple times. If no
Content-Length is set, data will automatically be encoded in HTTP Chunked
transfer encoding, so that server knows when the data ends. The
Transfer-Encoding: chunked header is added. Calling request.end()
is necessary to finish sending the request.】
encoding 参数是可选的,仅在 chunk 是字符串时适用。默认值为 'utf8'。
【The encoding argument is optional and only applies when chunk is a string.
Defaults to 'utf8'.】
callback 参数是可选的,当这段数据被刷新时将被调用,但仅在数据块非空时才会调用。
【The callback argument is optional and will be called when this chunk of data
is flushed, but only if the chunk is non-empty.】
如果所有数据都成功刷新到内核缓冲区,则返回 true。如果所有或部分数据被排队在用户内存中,则返回 false。当缓冲区再次空闲时,会触发 'drain' 事件。
【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.】
当 write 函数被调用时,如果传入空字符串或缓冲区,它不会做任何操作,并会等待更多输入。
【When write function is called with empty string or buffer, it does
nothing and waits for more input.】