小编use*_*085的帖子

如何使用request或http模块将gzip页面读入字符串

我发现js中的请求模块无法正确处理gzip或inflate格式的http响应.

例如:

request({url:'some url'}, function (error, response, body) {
   //if the content-encoding is gzip, the body param here contains binaries other than readable string. And even worse after you convert the body to buffer, u even can not gunzip it.
}
Run Code Online (Sandbox Code Playgroud)

所以我想在官方文档中使用示例代码.

var request = http.get({ host: 'izs.me',
                         path: '/',
                         port: 80,
                         headers: { 'accept-encoding': 'gzip,deflate' } });
request.on('response', function(response) {
  var output = fs.createWriteStream('izs.me_index.html');

  switch (response.headers['content-encoding']) {
    // or, just use zlib.createUnzip() to handle both cases
    case 'gzip':
      response.pipe(zlib.createGunzip()).pipe(output); …
Run Code Online (Sandbox Code Playgroud)

http zlib request node.js

13
推荐指数
2
解决办法
1万
查看次数

刷新eclipse cdt系统包括

我正在使用ecipse cdt开发c ++程序.问题是我将所有工作空间和eclipse包从turbolinux移动到centos linux.然后它引起一个问题,那就是系统包含的不同,但eclipse没有刷新包含路径.并且所有std容器类都无法解决.

有谁知道如何解决这个问题?

eclipse eclipse-cdt

8
推荐指数
1
解决办法
8160
查看次数

jsdom不处理网页内的脚本

我是nodejs的新手.我想使用jsdom来解析一些可能包含脚本代码的网页.但我得到错误表示函数或变量未定义.任何人都可以给出一些指示.

我的代码

var jsdom = require('jsdom');

jsdom.env({
  html: 'http://10.200.0.10:8080/test/a.html',
  scripts: [
    'http://code.jquery.com/jquery-1.5.min.js'
  ],
  done: function(errors, window) {
    var $ = window.$;
    window.onload();
    console.log(window.a);
  }
});
Run Code Online (Sandbox Code Playgroud)

和HTML页面在这里

<html>
<head>
    <script>
    var a = 0;
    function loads(){
        a=1000;
    }
    </script>
</head>
<body onload='loads()'>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

并在下面收到错误消息

dfddddfdf
undefined:1: ReferenceError: loads is not defined
loads()
^
ReferenceError: loads is not defined
    at unknown source
    at /root/node_modules/jsdom/node_modules/contextify/lib/contextify.js:10:24
    at /root/node_modules/jsdom/lib/jsdom/level1/core.js:1024:50
    at /root/testnode.js:18:12
    at Array.0 (/root/node_modules/jsdom/lib/jsdom.js:199:39)
    at EventEmitter._tickCallback (node.js:192:40)

node.js:201
        throw e; // process.nextTick error, or …
Run Code Online (Sandbox Code Playgroud)

html javascript node.js jsdom

5
推荐指数
1
解决办法
5648
查看次数

标签 统计

node.js ×2

eclipse ×1

eclipse-cdt ×1

html ×1

http ×1

javascript ×1

jsdom ×1

request ×1

zlib ×1