我正在尝试连接到在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地址。 不确定如何发送最后一部分,因为最后一部分它只是一个文本数据。
任何帮助将不胜感激...提前感谢
答案 0 :(得分:0)
您要将标头添加为有效负载。 UrlFetchApp提供了添加标头的方法。使用
var h = {
'method' : "post",
'headers' : header
};
var response = UrlFetchApp.fetch(url, h);
我不确定你的有效载荷是多少。在标题列表中,有一个空白标题 - 这是有效负载吗?如果是,则必须单独添加有效负载。
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);
注意:确保从标题列表中删除空白标题。