搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

Learn More

I'm using Google Apps Script1 to login to a website, except the intended page doesn't appear.

  • 2 个回答
  • 1 人有此问题
  • 5 次查看
  • 最后回复者为 cor-el

more options

I'm not certain if this is the appropriate forum. However, maybe someone understands header options and cookies.

If I execute the following google apps script I receive a blank dialog with a title of "demo", and a response code of 302. This dialog is attached.

If I next click on the "follow redirects" message I receive a error dialog, and this is also attached.

I'm kind of in the dark regarding authentication. Does someone know if there is a problem with the options, or if it's something else?

Thanks,


function logon0() {

 //
 // Logon to dashboard
 //
 var url = "https://www.######.com/login";
 var user = "######";
 var password = "######"; 
 var options = {muteHttpExceptions: true,
                followRedirects: false};
 options.headers = {"Authorization": "Basic " + Utilities.base64Encode(user + ":" + password) };
 var response = UrlFetchApp.fetch(url, options);
 var cookie = response.getAllHeaders()['Set-Cookie']; 
 var opt2 = {muteHttpExceptions: true,
             "headers":
                 {Cookie: cookie},
             followRedirects: false
            };
 var response2 = UrlFetchApp.fetch("https://www.######.com/app/v4/dashboard",opt2);
 var ui = HtmlService.createHtmlOutput(response2.getContentText());
 SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
 Logger.log(response2.getContentText());

}


I'm not certain if this is the appropriate forum. However, maybe someone understands header options and cookies. If I execute the following google apps script I receive a blank dialog with a title of "demo", and a response code of 302. This dialog is attached. If I next click on the "follow redirects" message I receive a error dialog, and this is also attached. I'm kind of in the dark regarding authentication. Does someone know if there is a problem with the options, or if it's something else? Thanks, -------------------------------------------------------------------------------------------------- function logon0() { // // Logon to dashboard // var url = "https://www.######.com/login"; var user = "######"; var password = "######"; var options = {muteHttpExceptions: true, followRedirects: false}; options.headers = {"Authorization": "Basic " + Utilities.base64Encode(user + ":" + password) }; var response = UrlFetchApp.fetch(url, options); var cookie = response.getAllHeaders()['Set-Cookie']; var opt2 = {muteHttpExceptions: true, "headers": {Cookie: cookie}, followRedirects: false }; var response2 = UrlFetchApp.fetch("https://www.######.com/app/v4/dashboard",opt2); var ui = HtmlService.createHtmlOutput(response2.getContentText()); SpreadsheetApp.getUi().showModelessDialog(ui,"demo"); Logger.log(response2.getContentText()); } -------------------------------------------------------------------------------------------------------
已附加屏幕截图

所有回复 (2)

more options

Do you have some reason to suspect that Lumosity supports basic access authentication? If it did, you wouldn't need any cookies. It looks like cookies are obtained via POST request to "www.lumosity.com/authentication" rather than requesting "www.lumosity.com/login"

Do you particularly want to do this with Lumosity, or is it just an example. It would be easier to start with a few that have a documented login process for learning purposes.

more options

This can happen if you open a website in a (i)frame and the website prohibits this via CSP.