Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:50:41+00:00 2026-06-05T09:50:41+00:00

I’m trying to write a simple script that fetches text from a webpage and

  • 0

I’m trying to write a simple script that fetches text from a webpage and processes that string. But, that website requires me to be logged in. I was successful in logging in to that website. This is how I logged in:

var payload = {"name1":"val1","name2":val2"};

var opt ={"payload":payload,"method":"post"};

var respose = UrlFetchApp.fetch("http://website.com/login",opt);

After logging in, the website places me in http://website.com/home. I checked response.getContentText() and I can confirm that I have been logged in successfully as it contains the text from http://website.com/home.
Now I need to get the contents of http://website.com/page and process it.
I first assumed the script can handle cookies by itself and proceeded with

var pagedata = UrlFetchApp.fetch("http://website.com/page);//Did not work

That obviously didnt work and pagedata.getContentText() says me to login first, which indicates cookies were not successfully passed..

I then tried to extract cookies which the server responded during login and to send it along with this request.

var cookie = response.getAllHeaders()['Set-Cookie'];     

// variable cookie now contains  a legitimate cookie.

// It contains 'JSESSIONID=blabla;Path=/' and 
// it is the ONLY cookie that server responds.

I tried to send that cookie in my page request.

var header = {'Cookie':cookie};

var opt2 = {"header":header};

var pagedata = UrlFetchApp.fetch("http://website.com/page",opt2);

I think even now cookies were not properly sent, as the content again says me to login.

Am I passing cookies correctly? I need help regarding the correct method of sending cookies in a request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:50:44+00:00Added an answer on June 5, 2026 at 9:50 am

    Here you can find cookies specification:
    http://www.w3.org/Protocols/rfc2109/rfc2109

    You have a potential issue in your code:
    response.getAllHeaders()[‘Set-Cookie’] can return either a string or a table of string if multiple ‘set-cookie’ attributes are sent back from the server.

    Eric is right, you cannot return the cookie without digesting it.

    Second error in your code:

    var opt2 = {"header":header};
    

    should be

    var opt2 = {"headers":header};
    

    Be aware also that GAS uses Google IPs. It can happen that two consecutive fetch use different IPs.
    The server your are connecting to may be session-IP dependant.

    Are you sure the server only send you back one cookie after an authentification ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.