request.write(chunk[, encoding][, callback])
chunk
<string> | <Buffer> | <Uint8Array>encoding
<string>callback
<Function>- 返回: <boolean>
发送一块正文。
此方法可以被多次调用。
如果没有设置 Content-Length
,则数据将自动使用 HTTP 分块传输编码进行编码,以便服务器知道数据何时结束。
Transfer-Encoding: chunked
标头会被添加。
需要调用 request.end()
来完成发送请求。
encoding
参数是可选的,仅当 chunk
是字符串时才适用。
默认为 'utf8'
。
callback
参数是可选的,将在刷新此数据块时调用,但前提是该块非空。
如果整个数据被成功刷新到内核缓冲区,则返回 true
。
如果所有或部分数据在用户内存中排队,则返回 false
。
当缓冲区再次空闲时,则将触发 'drain'
。
当使用空字符串或缓冲区调用 write
函数时,则什么都不做并等待更多输入。
chunk
<string> | <Buffer> | <Uint8Array>encoding
<string>callback
<Function>- Returns: <boolean>
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.
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.