Cookies are exchanged via GET/POST communication and login processing

Asked 2 months ago, Updated 2 months ago, 3 views

I am using Google apps script.

I am logging in to a site.

var LOGIN_URL="********"; 
var userid="********"; 
var password = "**********";
var source_URL = "**********";

var options = {
  method: "post",
  followRedirects: true,
  contentType: "applicationxml; charset=utf-8",
  payload: {
    userId: userid,
    password —Password
  }
};

var response=UrlFetchApp.fetch(LOGIN_URL, options);
var headers=response.getAllHeaders();

I set the options as above and logged in.
Also, in the header information obtained,

Set-Cookie=[Ljava.lang.Object;@6eee775a, Vary=Accept-Encoding, X-XSS-Protection=1; mode=block, Content-Type=text/html; charset=utf-8}

is available.
It is also stored in the variable cookies.

 if(typeof headers['Set-Cookie']!=='undefined'){
  var cookies = type of headers ['Set-Cookie'] == 'string' ? [ headers ['Set-Cookie' ] : headers ['Set-Cookie' ] ;
  for (vari=0;i<cookies.length;i++) {
      cookies[i] = cookies[i].split(';')[0];
  };
}

As a result

cookies[0]:tracking_code=eafdc5ca82ea6d8bfc0b1d147efc6efefe31e2f5
cookies[1]:_huntr_session_production=UEhGdDdVZVR5Ny8wL2JROGZwRFBFTTRjBYSklJUXBvdjNacFhlbUEyLzFCNHVhL0hrWWlVYUvb1drL094cDRGUUgraHVCbVV1Wk0yV2YV2YYYYWlV2YYRwTTM0M0R0RMY1R0R0RVY1R0R0R0MY1R0R0EhGblZmZXdxWDh1Qy8wcTd2QUJ3VWR5UXh5MUFselNWSjc5b1FTNHdnbWhPdFl6WkhybkRZM1JtSE5VQUZUZm91cExuT2h4UGtBbnQwbjVLTUtFeklCSVBmTU12RZTUZZTU12RZUZZT6WkFXFXFXFXFXFXFXT6WkUZUZUZUZUZ

It is shown that
Then pass cookies through the post method to perform the login process.

var options2={
  method: "get",
  followRedirects: true,
  headers:{
    Cookies: cookies.join(';')
  }
};

varsource=UrlFetchApp.fetch(source_URL, options2);
var headers2 = source.getAllHeaders();
var content=source.getContentText();

However, when you print content on a spreadsheet, you see HTML for pages that are not logged in.

The questions are as follows.
①Why are you not logged in?
⓶What part of the code should I change?
⓷If the code is not specifically incorrect, is the login process wrong in the first place (e.g., depending on the authentication method)?

If there is any missing information, I will reply to you.

I look forward to your kind cooperation.

javascript google-apps-script cookie https

2022-09-30 11:24

1 Answers

followRedirects: You may not be able to do it unless you handle the redirects one by one, not true.

CRSF tokens are mostly used in cookies.
The curl command does not include the cookie option.


2022-09-30 11:24

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.