Authenticate external restapi in meteor

Iam able to authenticate to external RestAPI using the following java code, iam wondering how to authenticate in Meteor. i tried with http package but ended up with the certificate error. Not sure what iam missing here? Appreciate for any pointers. thanks

      //create an instance of SSLContext:
            SSLContext mySSLContext = SSLContext.getInstance("SSL");
            //initialize the SSLContext with the TrustManager instance we created:
            mySSLContext.init(null, trustAllCerts, new;

            //Authenticate credentials **********************

            DefaultHttpClient httpclient = new DefaultHttpClient();
            CookieStore cookieStore = new BasicCookieStore();
            HttpContext localContext = new BasicHttpContext();
            localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            //Instantiate an object HttpGet with the URL of the server you want to connect, 
            HttpGet httpGetID = new HttpGet("https://localhost:9443/ccm/authenticated/identity");
            httpclient.execute(httpGetID, localContext);
            //to make sure that you created your cookies correctly, try to retrieve the saved information:
            List<Cookie> cookies1 = cookieStore.getCookies();
            for (Cookie cookie : cookies1) {
               System.out.println("\t" + cookie.getName() + " : " + cookie.getValue());

            //The next step is to authenticate with the j_security_check, using a valid username and password credentials.
            //For this step, we use the Apache HttpClient class NameValuePair:
            List<NameValuePair> authFormParams = new ArrayList<NameValuePair>();
            authFormParams.add(new BasicNameValuePair("j_username", "Myusername"));
            authFormParams.add(new BasicNameValuePair("j_password", "Mypassword"));
            UrlEncodedFormEntity encodedentity = new UrlEncodedFormEntity(authFormParams,
            HttpPost httpPostAuth = new HttpPost("https://localhost:9443/ccm/authenticated/j_security_check");

            httpclient.execute(httpPostAuth, localContext);
            //to display the cookie data
            List<Cookie> cookies2 = cookieStore.getCookies();
            for (Cookie cookie : cookies2) {
                  System.out.println("\t" + cookie.getName() + " : " + cookie.getValue());

The following is the Meteor Code i have tried:

var result ="GET", https://localhost:9443/ccm/authenticated/identity,
                            console.log("result is" + JSON.stringify(result));
                            //console.log("myresult"  + result);

                            console.log("error is" + error);

                       console.log("my result" + result);   
        var result1 ="POST", https://localhost:9443/ccm/authenticated/j_security_check,
                     {auth: {j_username: 'MyUserName',j_password: 'MyPassword' }

What is the error you’re getting?

currently i am getting the status code 302. i have put the code on meteor pad. Not sure what is missing, iam able to get the proper output on firefox poster and chrome advanced rest api. thanks

You’re stopping at a redirect. Try explicitly telling to followRedirects:

...'POST', geturl, {
  headers: { "Accept": "application/json","OSLC-Core-Version": "2.0" },
  followRedirects: true

I know the docs say the default is true, but I think they might be wrong.

Thanks a lot @hwillson. now the status code problem gone, but i am not able to authenticate onto rest service, using the same credentials i am able to, using the Firefox poster and chrome Advanced Rest client application. the following are the steps i followed in chrome Advanced Rest client application. I assume the first request sending some cookies, does meteor handles the cookies just like the browser. Appreciate your help. (code on meteor pad)

  1. used the following url with the headers using POST method:

  2. used the following url with the headers using GET method: