我試圖發佈並獲取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?
向任何建議打開。