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

后端 未结 2 1191
抹茶落季
抹茶落季 2020-11-28 08:36

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 i

相关标签:
2条回答
  • 2020-11-28 09:23

    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 讨论(0)
  • 2020-11-28 09:30

    It looks like you are setting the headers correctly in UrlFetchApp.fetch().

    I believe that the data in the Set-Cookie header is in a different format than the data that is expected in Cookie header. For example, Set-Cookie contains information about expiration, etc.

    0 讨论(0)
提交回复
热议问题