login and fetch url Google Apps Script

久未见 提交于 2021-02-08 10:49:42

问题


I am trying to fetch data from this website into my google spreadsheet using Google Apps Scripts: https://net.statev.de/#/pages/buisness/storage/5aec8c9a3b82972b99e741c6

And need to login here first: https://net.statev.de/#/login

This is the function i came up with:

function fetch() {
var loginURL = 'https://net.statev.de/#/login';
  var dataURL = 'https://net.statev.de/#/pages/buisness/storage/5aec8c9a3b82972b99e741c6';
  var loginPayload = {
     'email':'testmail',
     'password':"test",
  };
  var loginOptions = {'method':'post','payload':loginPayload,'followredirects':false};
  var loginResponse = UrlFetchApp.fetch(loginURL,loginOptions);

  var loginHeaders = loginResponse.getAllHeaders();
  var cookie = [loginResponse.getAllHeaders()["Set-Cookie"]];
  cookie[0] = cookie[0].split(";")[0];
  cookie = cookie.join(";");

  var dataHeaders = {'Cookie':cookie};
  var dataOptions = {'method':'get','headers':dataHeaders};
  var dataResponse = UrlFetchApp.fetch(dataURL,dataOptions);

  Logger.log(dataResponse);
}

My problem here is, I only get 404 Error from the UrlFetchApp.fetch and i don't really get what I am doing wrong. Is it possible that the website blocks my fetch request?


回答1:


The registration form doesn't work, so I couldn't test this. That said, it seems that you are not calling the correct authorization endpoint. You can use Chrome Dev Tools as a network sniffer

It's extremely likely that using just the login & password combo will not do the job - if it does work, the website you link to is lousily programmed and not secure.

To sum up, here's the data:

https://net.statev.de/auth/login

Payload properties

 {"password": password, "username": username}


来源:https://stackoverflow.com/questions/50305688/login-and-fetch-url-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!