0

I am trying to fetch information from a site with basic authentication (username and password), I followed documentation and some forums here, but I can't get it to work.

Whenever I run the function, it returns the HTML from the login website, as if the authentication isn't working.

function getRequest() {

var url = "URL";
var username = "USER";
var password = "PASSWRD";

var headers = {
    "Authorization" : "Basic " + Utilities.base64Encode(username + ":" + password)
};

var params = {
  "method":"GET",
  "headers": headers
};
    
const response = UrlFetchApp.fetch(url, params);

Logger.log(response.getContentText());

}

I need it to return the contents from the website already logged in.

3
  • 1
    How do you know the the site that you are calling accepts GET calls with basic authentication?
    – Wicket
    Commented Aug 26, 2022 at 19:38
  • I use a text expander tool called TextBlaze, and it does allow me to send HTTP requests. I can do it easily with it, it's just I need to make extra steps to use that tool and check the website, so I'd like to do the same thing with GAS.
    – Charlie
    Commented Aug 29, 2022 at 18:22
  • Can't see anything wrong with your script. If we need to dig further, you need to provide more debugging details: 1.your tool's(Textblaze) screenshots, 2. your browser requests screenshots and text of the actual request, 3.the html retrieved in apps script.
    – TheMaster
    Commented Aug 29, 2022 at 22:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.