Cookies 谷歌应用程序脚本==>;UrlFetchApp、方法GET和cookie

Cookies 谷歌应用程序脚本==>;UrlFetchApp、方法GET和cookie,cookies,google-apps-script,urlfetch,Cookies,Google Apps Script,Urlfetch,我使用UrlFetchApp发送用户和pwd(方法POST)。获取cookie后,在其他请求中使用(方法get)。但是这个新请求不起作用,我认为这个cookie在这个新请求中没有正确的用途。有人能帮我吗 var opt ={ "method":"post", "User-Agent" : "Mozilla/5.0", "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

我使用UrlFetchApp发送用户和pwd(方法POST)。获取cookie后,在其他请求中使用(方法get)。但是这个新请求不起作用,我认为这个cookie在这个新请求中没有正确的用途。有人能帮我吗

  var opt ={
    "method":"post",
    "User-Agent" : "Mozilla/5.0",
    "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language" : "en-US,en;q=0.5",    
    "payload": this.payload.toString(), 
    "followRedirects" : false
  };
  var response = UrlFetchApp.fetch("https://edas.info/addTopic.php?c=19349",opt);
  var resp1=response.getContentText();    
  Logger.log(resp1);  
  response.getResponseCode();

  var headers = response.getAllHeaders();
  var cookies = headers['Set-Cookie']; 
  for (var i = 0; i < cookies.length; i++) {
    cookies[i] = cookies[i].split( ';' )[0];
  };


  opt = {
    "method" : "get",
    "User-Agent" : "Mozilla/5.0",
    "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language" : "en-US,en;q=0.5",    
    "headers": {
      "Cookie": cookies.join(';')
    },
    "followRedirects" : false    
  };
  response = UrlFetchApp.fetch("https://edas.info/addTopic.php?c=19349", opt);
  var resp1=response.getContentText();  
  Logger.log(resp1);  
var opt={
“方法”:“发布”,
“用户代理”:“Mozilla/5.0”,
“接受”:“text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”,
“接受语言”:“en-US,en;q=0.5”,
“payload”:this.payload.toString(),
“followRedirects”:false
};
var response=UrlFetchApp.fetch(“https://edas.info/addTopic.php?c=19349“,选择);
var resp1=response.getContentText();
Logger.log(resp1);
response.getResponseCode();
var headers=response.getAllHeaders();
var cookies=标题['Set-Cookie'];
对于(变量i=0;i
对于您的问题,我无法提供具体的帮助,但这里有一个指针

正如它所说:

还要注意,GAS使用谷歌IPs。两个连续的获取可能使用不同的IP。您连接的服务器可能依赖于会话IP

您的代码是否在本地开发服务器上运行,并且仅在部署到App Engine时失败?
还是本地也会失败?

首先,感谢您提供的代码片段,这让我开始用这样的脚本处理cookie。我遇到了一个可能是你的问题。有时网页返回一个cookie数组,然后代码就可以正常工作了。有时它返回单个字符串(而不是一个字符串数组)。因此,我必须通过以下测试消除歧义:

if ( (cookies != null) && (cookies[0].length == 1) ) {
      cookies = new Array(1);              
      cookies[0] = headers['Set-Cookie']; 
}

我想知道你是否设法使你的声明生效。我遇到了类似的问题。您是否能够更改
用户代理