我试图发布并获取cookie。我是新手,这对我来说是一个学习项目。我的印象是,如果您使用'set-cookie',则应该能够在.toSource中看到额外的'set-cookie'。 (我试图在Google Apps网站上完成此操作,如果这有所帮助)。我错过了什么?这里是我的代码:Google Apps脚本和Cookie
function setGetCookies() {
var payload = {'set-cookie' : 'test'};
var opt2 = {'headers':payload, "method":"post"};
UrlFetchApp.fetch("https://sites.google.com/a/example.com/blacksmith", opt2);
var response = UrlFetchApp.fetch("https://sites.google.com/a/example.com/blacksmith")
var openId = response.getAllHeaders().toSource();
Logger.log(openId)
var AllHeaders = response.getAllHeaders();
for (var prop in AllHeaders) {
if (prop.toLowerCase() == "set-cookie") {
// if there's only one cookie, convert it into an array:
var myArray = [];
if (Array.isArray(AllHeaders[prop])) {
myArray=AllHeaders[prop];
} else {
myArray[0]=AllHeaders[prop];
}
// now process the cookies
myArray.forEach(function(cookie) {
Logger.log(cookie);
});
break;
}
}
}
在此先感谢!我引用这个来开发代码:Cookie handling in Google Apps Script - How to send cookies in header?
向任何建议打开。