开发者

Why does node.js append '0' to my POST request?

Consider the following very simple node.js script:

http = require('http')

  options =
{
  host:'localhost',
  port:8000,
  method:'POST'
}

req = http.request(options)
req.end()

When I tell netcat to listen on port 8000 then execute the script, netcat produces the following:

POST / HTTP/1.1
Host: localhost:8000
Connection: close
Transfer-Encoding: chunked

0

What's with the trailing zero? Note that this is开发者_JAVA技巧 not an artifact introduced by netcat.


It's using chunked encoding as you can see by the header. Basically it sends the length of a block of bytes as text followed by that block. In your case it's sending a zero length block.

This is part of standard http/1.1 see http://en.wikipedia.org/wiki/Chunked_transfer_encoding

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜