2

I am trying to request data from ALM using Node JS, following is my code. I am receiving empty response from ALM, when I try same link in browsers it returns correct response with all the defects after login.

options = {
    // host : 'alm:8080', 
    host: 'alm',
    port:'8080',
    path : "/qcbin/authentication-point/authenticate",
    method: "GET",
    headers : {'Content-Type': 'application/XML','Authorization': 'Basic '+new Buffer('user' + ':' + 'pass').toString('base64')}
};

ALMConnect(){
    process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
    var req = https.request(this.options, function(res){
        console.log('Cookie in session 1: '+ res.headers["set-cookie"]);
        var opt = {
            host: "alm",
            port:"8080",
            path: "/qcbin/rest/domains/"+"Test"+"/projects/"+"Test"+"/defects?login-form-required=y&apos",
            method:"GET",
            headers: {"Cookie":res.headers["set-cookie"]}
        };
        res.setEncoding('utf8');
        var output='';
        extractDefects(opt);

        function extractDefects(opt){

            //get all the fields that you want to query. Lesser the fields smaller the XML returned, faster is the call.

            var req2 = https.request(opt, function(res1){
                res1.setEncoding('utf8');
                var output='';
                res1.on('data',function(chunk){
                    output+=chunk;
                });
                res1.on('end',function(){
                    console.log('the message is reg2 '+ output);
                });
            });
            req2.on('error',function(e){
                console.log('the erro msg reg2'+ e);
            });
            req2.end();
        }
    });
    req.on('error',function(e){
    console.log('the erro msg'+ e);
    });
    req.end();
}
  • What's the error message? try to use one the promise ```.catch(function(error){ throw new Error(error); })``` How about that? ```new Buffer('user' + ':' + 'pass')``` is it expected? – GwenM Jun 17 '20 at 14:07
  • I am using native http request, as far as I know promise is not supported. It seems I am getting any error because I am getting "this message is reg2" printed, it seems output is not being populated. – ThatIndianNerd Jun 17 '20 at 14:25
  • What do you get in ```chunk``` and ```res1```? – GwenM Jun 17 '20 at 14:38
  • It seems it is not even going in res1.on('data',function(chunk) – ThatIndianNerd Jun 17 '20 at 14:46
  • My rest is not working because I am using incorrect uri. I need to remove '?login-form-required=y&apos' from my second call. Now it is new problem, it seems it is not logging in with the cookie, getting 401 error. – ThatIndianNerd Jun 17 '20 at 14:50
  • @ThatIndianNerd did this issue get resolved?, I'm also facing the same issue but could not really understand why? – Ravi Mar 22 '21 at 09:35

0 Answers0