【问题标题】:HTTP POST and RESPONSE specific case studyHTTP POST 和 RESPONSE 特定案例研究
【发布时间】:2011-11-03 15:56:13
【问题描述】:
  1. 网站:http://na.leagueoflegends.com/ladders/solo-5x5
  2. 搜索玩家(例如:Jaiybe)
  3. 您会被重定向(在本例中为:http://na.leagueoflegends.com/ladders/solo-5x5?highlight=28&page=1
  4. 阅读内容

我想在 java/android 中这样做。

  1. 我在搜索时分析网站的POST请求,结果:

    • 操作:搜索
    • 玩家:Jaybe
    • ladder_id:3
    • form_build_id:form-fff5e6e2569f1e15e5a5caf2a61c15e2
    • form_id:ladders_filter_form
  2. 构建一个简单的 HTTP POST 混合并让我们读取内容...

代码:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://na.leagueoflegends.com/ladders/solo-5x5");

// Add your POST METHOD attributes
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("op", "Search"));
nameValuePairs.add(new BasicNameValuePair("player", Jaiybe));
nameValuePairs.add(new BasicNameValuePair("ladder_id", "3"));
nameValuePairs.add(new BasicNameValuePair("form_build_id","form-daca6fff89cedc352ccc3f533afa3804"));
nameValuePairs.add(new BasicNameValuePair("form_id","ladders_filter_form"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
return responseBody;

当我运行它时 - 我得到了某种离线页面...

数字form_build_id - 不断变化,但这没问题,仍然使用相同的,而且如果我想“测试”这是否可能是问题,我不知道我会如何.. .

或者:是否有任何其他 - 快速 - 方法如何获得相同的结果?

奇怪的是,我在 android 上得到的“错误”站点源代码是不同的,就好像我在我的 PC(Win7、Eclipse、Java)或浏览器中运行的一样。好像会有两个版本的离线站点 - 用于移动和 PC - 但我的问题是:服务器如何知道代码在 Android 设备上运行?有没有办法在 HttpClient 中进行设置?

【问题讨论】:

标签: android http http-post response httpresponse


【解决方案1】:
form_build_id:form-fff5e6e2569f1e15e5a5caf2a61c15e2

这是一个自动生成的令牌,在特定时间段内有效。这可能是您的问题的根源,也是令牌首先存在的原因(以防止垃圾邮件)。

由于此令牌似乎不是基于会话的,因此您实际上可以在生成表单的页面上使用 HTTP Get,并为您的 HTTP Post 每次解析生成的令牌。

关于操作系统检测,浏览器通常使用HTTP User-Agent 标头提供有关操作系统的信息。

【讨论】:

  • 好吧,有没有办法处理这个令牌?
  • 正如我已经提到的,您每次都需要从na.leagueoflegends.com/ladders/solo-5x5 解析出令牌。不过,我建议你联系 Riot 了解他们对此的立场。
  • 我在 java (Eclipse PC) 中一直使用相同的令牌并且它可以工作。不要认为这将是问题。
猜你喜欢
  • 2012-01-23
  • 2020-11-08
  • 2020-10-25
  • 1970-01-01
  • 2010-09-25
  • 2019-07-12
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多