Cookies are exchanged via GET/POST communication and login processing

Asked 5 months ago, Updated 5 months ago, 22 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


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

var options2={
  method: "get",
  followRedirects: true,
    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

© 2023 OneMinuteCode. All rights reserved.