没有通过节点js中的http请求获得响应

时间:2018-04-20 07:01:15

标签: node.js http curl

     var http    = require("http");   
     var util    = require("util");    
     var username   = "user";
     var password  = 'pass';

    http.request({
            host: "127.0.0.1",
            port:"8332",
            path:"/path",
            method: "POST",
            headers: {                   
                "Authorization": "Basic " + new Buffer( username + ":" + password ).toString('base64')
            },
             postData: {
                mimeType: 'application/x-www-form-urlencoded',
                params: [
                  {
                    jsonrpc: '1.0',
                    id: 'curltest',
                    method:'decoderawtransaction',
                    params:'010000000157065146a6b32b224b87d47c1b0283b1ae2fa5bd4f9af9ebc45928110f87fbae0000000070004830450'
                  }         
                ]
              }
        },
        function(res){
            console.log(util.inspect(res, false, null));          

            var response = "";

            res.on('data', function(chunk){
                response += chunk;
                console.log("res"+response);
            });

            res.on('end',function(){
                response = JSON.parse(response);
                console.log("res1"+response); 
            });

    }).end();

我试图通过http请求获得基本auth和参数的响应,但我不响应,我怎么能通过这个方法得到结果, 如果有其他任何流程请帮助我..

0 个答案:

没有答案