2012-06-17 6 views
1

게시하고 쿠키를 가져 오려고합니다. 나는 초보자이며 이것은 나를위한 학습 프로젝트입니다. 내 인상은 당신이 'set-cookie'를 사용하면 .toSource에서 추가 'set-cookie'를 볼 수 있어야한다는 것이다. (차이를 만드는 경우 Google Apps 사이트에서이를 수행하려고합니다.) 내가 누락 되었습니까? 여기 내 코드 :Google Apps 스크립트 및 쿠키

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?

어떤 조언이 있어도 열람 할 수있다.

답변

1

Google 사이트에 로그인하지 않으면 응답에 쿠키가 설정되지 않습니다. UrlFetchApp는 Google 쿠키를 전달하지 않으므로 로그 아웃 한 것처럼 작동합니다.

0

먼저 'test'라는 이름으로 보내려는 쿠키에는 값이 없습니다. 'test = somevalue'를 보내야합니다.

둘째, 쿠키를 Google 서버로 보내고 이전에 보낸 동일한 쿠키로 답장 해달라고 요청하는 중입니까?

나는 당신이 HTTP 클라이언트 인 것처럼 HTTP 서버로 행동하려고한다고 생각합니다. HTTP 클라이언트로서 역할은 HTTP 서버가 이전에 보낸 쿠키 (도메인 존중, 만료 ... 매개 변수) 만 되돌려 보내는 것입니다.

관련 문제