2

I want to re-use cookie got from the response of one post request in further post requests.In the following server-side code I'm getting the cookie as JSON Object

 Meteor.methods({
   'login':function(){
      var cookieData = "";
      var loginUrl = "http://somesite.com/login.page";
      var loginData = {params:{username:"myUserName",password:"mySeceret"},headers:{"User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:31.0) Gecko/20100101 Firefox/31.0"}};
      var homePage = HTTP.post(loginUrl,loginData);
      var cookieData = homePage.headers["set-cookie"];
      var secondPageUrl = "http://somesite.com/scond.page"
      var postData  = {params:{param1:"value1",param2:"value2"},headers:{Cookie:cookieData,"User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:31.0) Gecko/20100101 Firefox/31.0"}};
      var secondResponse = HTTP.post(secondPageUrl,postData);
    }
   })

I'm getting the secondResponse.statusCode as 302 instead of 200.
The variable cookieData is a JSON object, Now how to use the content of cookieData in further post requests ?

SG_
  • 1,316
  • 14
  • 26

1 Answers1

1

Since the cookieData is a JSON object, you might have to convert it into a string when you pass it into the Cookie property of the second request's header. Try that.

rclai
  • 1,880
  • 14
  • 25