Tag: 内容长度

Nodejs不同的内容长度

我正在从互联网上下载一个图像(来自Box),并且我得到了不同的body.length和头部content-length 。 响应头的content-length等于75739 。 但是body.length等于72818 。 现在看看这个,如果我运行request(url).pipe(fs.createWriteStream('image.jpg')) ,图像得到了75739并正确打开。 另外,如果我运行fs.writeFileSync('image.jpg', body) ,图像得到137515,并没有正确打开。 我也做了这个要点,所以你可以自己testing: https : //gist.github.com/Daymannovaes/54663e0718f0ded40285d0666f937179 我不知道是否编码是问题,但我试图得到与所有的编码字节长度,没有一个是正确的大小: length of the body (ascii) 72818 length of the body (utf8) 137515 length of the body (utf16le) 5636 length of the body (ucs2) 145636 length of the body (base64) 54613 length of the body (latin1) 72818 length of the […]

限制Node.js中的请求中的主体内容长度

代码很简单。 我只对youtube.com源代码的第一部分感兴趣,例如,当内容长度高于10000时,我想停止下载数据。 我一直在试图做到没有成功。 有任何想法吗? var request = require('request'); var cheerio = require('cheerio'); var url = 'https://www.youtube.com/'; request(url, function(err, resp, body) { if (err) throw err; $ = cheerio.load(body); });

节点Express内容长度

我使用node.js并在一个小的项目中expression。 我设置响应头像打击: res.set({'Content-Type':'text/plain;charset=utf-8', 'Content-Length': Buffer.byteLength(data, 'utf-8')}); 我可以用console.log打印数据的长度是317。 但在浏览器的控制台,我只是得到这些: 连接:保持活跃 内容编码:gzip 内容types:文本/无格式;字符集= utf-8的 date:2013年6月1日星期六08:21:59 GMT 传输编码:分块 有所不同:接受编码 X-已启动方式:快递 那么,为什么内容消失?