Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解码node.js中的https响应数据_Node.js - Fatal编程技术网

解码node.js中的https响应数据

解码node.js中的https响应数据,node.js,Node.js,在node.js中使用https时,我在读取响应数据时遇到了问题。以下是https请求的代码 https.get(options, function(resp) { console.log(resp.headers) //working fine resp.on('data', function(d) { console.log(d) // buffered da

在node.js中使用https时,我在读取响应数据时遇到了问题。以下是https请求的代码

https.get(options, function(resp) {                     
    console.log(resp.headers)        //working fine
    resp.on('data', function(d) {           
        console.log(d)             // buffered data; like <Buffer 7b 22 69...
        process.stdout.write(d);  // working fine(prints decoded data in console)
        var decoded_data=???    }); 
}).on('error', function(e) {
    console.error(e);
});
https.get(选项、函数(resp){
console.log(resp.headers)//工作正常
关于('data',函数(d){
log(d)//缓冲数据;如
或者,早些时候:

resp.setEncoding('utf8');
然后,所有关于
事件的
都将为您提供一个字符串,而不是一个缓冲区

resp.setEncoding('utf8');