0

我正在尝试连接到在 Flash 游戏中退出的表格分数。使用浏览器时,我发送的标题是这个

POST /game/json?h=c1234567890f HTTP/1.1
Host: pt3.forgeofempires.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: sid=awsndax7nsow; req_page_info=game_v1; start_page_type=game; start_page_version=v1
Connection: keep-alive
Referer: http://cdn.pt.forgeofempires.com/swf/Main.swf?123456789
Content-type: application/x-www-form-urlencoded
Content-length: 161

34c4ceb6d8[{"requestClass":"ClanService","requestMethod":"getOwnClanData","requestData":[],"requestId":1,"__class__":"ServerRequest","clientVersionNumber":0.31}]

找了一会儿(我在 JavaScript 中的承认不是那么高),我确实找到了一些示例,在理解它们之后,我确实编写了自己的代码。

function test(){
  var header =
      {
        'Host': 'pt3.forgeofempires.com',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'en-US,en;q=0.5',
        'Accept-Encoding': 'gzip, deflate',
        'Cookie': 'sid=awsndax7nsow; req_page_info=game_v1; start_page_type=game; start_page_version=v1',
        'Connection': 'keep-alive',
        'Referer': 'http://cdn.pt.forgeofempires.com/swf/Main.swf?123456789',
        'Content-type': 'application/x-www-form-urlencoded',
        'Content-length': '161',
        '': '96c4ceb6d9[{"requestClass":"ClanService","requestMethod":"getOwnClanData","requestData":[],"requestId":4,"__class__":"ServerRequest","clientVersionNumber":0.31}]'
      }

  var url = "http://pt3.forgeofempires.com/game/json?h=c1234567890f";
  var h = {
    'method'  : "post",
    'payload' : header
  };
  var response = UrlFetchApp.fetch(url, h);
  return response;
}

当我运行代码时,它总是进入登录页面。不确定这是因为任何脚本错误还是简单的因为它是访问我的帐户的不同 IP 地址。不知道如何发送最后一部分,因为最后一部分只是文本数据。

任何帮助将不胜感激...在此先感谢

4

1 回答 1

0

You are adding your headers as a payload. UrlFetchApp provides a way to add headers. Use that

var h = {
    'method'  : "post",
    'headers' : header
  };
  var response = UrlFetchApp.fetch(url, h);

I'm not sure what your payload is. In the list of headers, there is a blank header - is this the payload ? If yes, then you have to add the payload separately.

var h = {
    'method'  : "post",
    'headers' : header,
    'payload' : '96c4ceb6d9[{"requestClass":"ClanService","requestMethod":"getOwnClanData","requestData":[],"requestId":4,"__class__":"ServerRequest","clientVersionNumber":0.31}]'
  };
  var response = UrlFetchApp.fetch(url, h);

Note: Ensure that you remove the blank header from the list of headers.

于 2013-04-26T04:51:53.413 回答