title: Google script to login, retrieve cookie and get csv to sheets
body: <p>I can get the cookie with curl -d "_u=user_name" -d "_p=password" --cookie-jar ./cookie <a href="https://url.tologin.com/admin/login" rel="nofollow noreferrer">https://url.tologin.com/admin/login</a> successfully but can't do the same with google script</p>
  
  <pre><code>function myFunction() {
    var payload = {"_u" : "user_name","_p" : "password"};
    var opt ={"payload":payload,"method":"post"};
    var response = UrlFetchApp.fetch("https://url.tologin.com/admin/login",opt);
    var headers = response.getAllHeaders(); 
    Logger.log(headers);
    var cookie = headers['Set-Cookie'];     
    Logger.log(cookie);
    Logger.log(response);
    response.getContentText();  
  
    var header = {'Cookie':cookie};
  
    var opt2 = {"headers":header};
  
    var pagedata = UrlFetchApp.fetch("https://url.tologin.com/admin/sales/order/export/csv",opt2);
    Logger.log(pagedata);
  }
  </code></pre>
  
  <p>I get answer from webserver with failed login page and I can't figure out what is wrong with google script</p>