Cookie handling in Google Apps Script – How to send cookies in header?

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 ?

Leave a Comment