Help with http request

Guys, I’m trying to make a code that accesses a system here from my company by http request

I’m getting the cookies with the get and works with the first post, but I still need to do some other posts in sequence, but from the second post, it does not work anymore … already tried synchronously and asynchronously, none of them works .

can anybody help me ?

here is the code:

 var get = HTTP.get('https://sigaa.ufpb.br/sigaa/index.jsf'); 
  var cookie = get.headers['set-cookie'][0];
  var teste = cookie.replace('; Path=/; Secure', '');

// FIRST POST
var post1 = HTTP.post(‘https://sigaa.ufpb.br/sigaa/index.jsf’, {
headers: {
“Accept”: “text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”,
“Accept-Encoding”: “gzip, deflate, br”,
“Accept-Language” : “pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3”,
“Connection” : “keep-alive”,
“Content-Length”: 141,
“Content-Type”: “application/x-www-form-urlencoded”,
“Cookie” : “_ga=GA1.2.1039691157.1535891476; _gid=GA1.2.2131143470.1536537350;” + teste + “”,
“Host” : “sigaa.ufpb.br”,
“Upgrade-Insecure-Requests”:1,
“User-Agent”: “Mozilla/5.0 (Windows NT 6.1; rv:62.0) Gecko/20100101 Firefox/62.0”
},
params: {
“form” : “form”,
“form:width” : 1366,
“form:height” : 768,
“form:login” : “hopemissoe”,
“form:senha” : “1705hop”,
“form:entrar” : “entrar”,
“javax.faces.ViewState” : “j_id1”
},

  });

// SECOND POST

  var cookie2 = post1.headers['set-cookie'][0];
  var teste2 = cookie2.replace('; Path=/; Secure', '');
  console.log(post1);
  //console.log("entrouuuuuuuuuuuuuuuuuuuu");
  console.log(teste2);

 var post2 = HTTP.post('https://sigaa.ufpb.br/sigaa/vinculos.jsf', { 
   headers: {
     "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
     "Accept-Encoding": "gzip, deflate, br",
     "Accept-Language" : "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
     "Connection" : "keep-alive",
     "Content-Length": 166,
     "Content-Type": "application/x-www-form-urlencoded", 
     "Cookie" : "_ga=GA1.2.2098433725.1526135029; __utmz=127220425.1532984003.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=127220425.2098433725.1526135029.1535057435.1535489910.8; _gid=GA1.2.1755411025.1536772259;" + teste2 + "",
     "Host" : "sigaa.ufpb.br",
     "Origin": "https://sigaa.ufpb.br",
     "Referer": "https://sigaa.ufpb.br/sigaa/vinculos.jsf",
     "Upgrade-Insecure-Requests":1,
     "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
    },
    params: {
      "j_id_jsp_1522167007_1": "j_id_jsp_1522167007_1",
      "javax.faces.ViewState" : "j_id1",
      "j_id_jsp_1522167007_2j_id_2": "j_id_jsp_1522167007_2j_id_2",
      "vinculo": 3,
      "identificador": "011.958.013-60"
                        
   }, 

  });
  //console.log(post2);  
  return post2;