我正在编写一个应用程序来检查公交车时刻表。因此,我需要将一些数据发布到html页面,提交它,然后使用htmlparser解析生成的页面。
虽然可能会被问到很多,但有人能帮我确定1)这个页面是否支持post/get (我想它支持) 2)我需要使用哪些字段? 3)如何发出实际的请求?
这是我到目前为止的代码:
String url = "http://busspur02.aseag.de/bs.exe?Cmd=RV&Karten=true&DatumT=30&DatumM=4&DatumJ=2010&ZeitH=&ZeitM=&Suchen=%28S%29uchen>0=&HT0=>1=&HT1=";
String charset = "CP1252";
System.out.println("startFrom: "+start_from);
System.out.println("goTo: "+destination);
//String tag.v
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("HTO", start_from));
params.add(new BasicNameValuePair("HT1", destination));
params.add(new BasicNameValuePair("GTO", "Aachen"));
params.add(new BasicNameValuePair("GT1", "Aachen"));
params.add(new BasicNameValuePair("DatumT", day));
params.add(new BasicNameValuePair("DatumM", month));
params.add(new BasicNameValuePair("DatumJ", year));
params.add(new BasicNameValuePair("ZeitH", hour));
params.add(new BasicNameValuePair("ZeitM", min));
UrlEncodedFormEntity query = new UrlEncodedFormEntity(params, charset);
HttpPost post = new HttpPost(url);
post.setEntity(query);
InputStream response = new DefaultHttpClient().execute(post).getEntity().getContent();
// Now do your thing with the facebook response.
String source = readText(response,"CP1252");
Log.d(TAG_AVV,response.toString());
System.out.println("STREAM "+source);编辑:
这是我的新代码:
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://busspur02.aseag.de/bs.exe?SID=5FC39&ScreenX=1440&ScreenY=900&CMD=CR&Karten=true&DatumT="+day+"&DatumM="+month+"&DatumJ="+year+"&ZeitH="+hour+"&ZeitM="+min+"&Intervall=60&Suchen=(S)uchen>0=Aachen&T0=H&HT0="+start_from+">1=Aachen&T0=H&HT1="+destination+"";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
//do something with the response
Log.i("GET RESPONSE",EntityUtils.toString(resEntityGet));
}
} catch (Exception e) {
e.printStackTrace();
} 但是输出文件被截断了。如果我在浏览器中执行相同的请求,我会得到14条不同的路由。现在文件突然停止了,我只得到了3条路由...怎么了?
我用截断字符串解决了最后一个问题:click here to see my solution
发布于 2010-04-30 09:45:15
您好!
在以下摘录中:
<td class="Start3">
<input type="text" name="GT0" value="" tabindex="1" />
</td"class=start3“指示浏览器以特定的方式格式化表格和数据。您感兴趣的是从该表单生成的"GET“url上的">0=your文本片段”。
https://stackoverflow.com/questions/2741755
复制相似问题