【发布时间】:2011-11-03 15:56:13
【问题描述】:
- 网站:http://na.leagueoflegends.com/ladders/solo-5x5
- 搜索玩家(例如:Jaiybe)
- 您会被重定向(在本例中为:http://na.leagueoflegends.com/ladders/solo-5x5?highlight=28&page=1)
- 阅读内容
我想在 java/android 中这样做。
-
我在搜索时分析网站的POST请求,结果:
- 操作:搜索
- 玩家:Jaybe
- ladder_id:3
- form_build_id:form-fff5e6e2569f1e15e5a5caf2a61c15e2
- form_id:ladders_filter_form
构建一个简单的 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