HttpClient POST fails to submit the form + resulting string is cut-off (incomplete)
- by Jayomat
Hi,
I'm writing an app to check for the bus timetable's. Therefor I need to post some data to a html page, submit it, and parse the resulting page with htmlparser.
Though it may be asked a lot, can some one help me identify if
1) this page does support post/get (I think it does)
2) which fields I need to use?
3) How to make the actual request?
this is my code so far:
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);
EDIT:
This is my new code:
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();
}
But the output file is cut-off. If I do the same request in a browser I get like 14 different routes. Now the file suddenly stops and I only get 3 routes.... what's wrong?
04-30 12:19:12.362: INFO/GET RESPONSE(256): <!-- Ausgabebereich (automatisch erzeugt) -->
04-30 12:19:12.362: INFO/GET RESPONSE(256): <div align="center">
04-30 12:19:12.362: INFO/GET RESPONSE(256): <p></p>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <p>Ihr Fahrplan für die Verbindung von Aachen, Kaiserplatz nach Aachen, Karlsgraben am Freitag, den 30.04.2010 (Koniginnedag), Abfahrten ab 12:19 Uhr</p>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <table class="Result">
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="fussnote">Fussnote</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="fahrzeug">Fahrzeug</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="abfahrt">Abfahrt</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="haltestellean">Haltestelle</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="linie">Linie</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="haltestelleab">Haltestelle</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="ankunft">Ankunft</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <th class="fahrzeit">Fahrzeit/Tarif</th>
04-30 12:19:12.362: INFO/GET RESPONSE(256): </tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <td> </td><td> <img src="http://www.busspur.de/logos/efa-bus.gif" title="Niederflurbus"></td><td>12:23</td><td title="lc0">Aachen, Kaiserplatz [Heinrichsalle Ri. Hansemannplatz] <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_kaiserplatz.pdf">Umgebungsplan</a></td><td>45</td><td title="lc0">Aachen, Karlsgraben <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_karlsgraben.pdf">Umgebungsplan</a></td><td>12:34</td><td>00:11 / Â 1,00</td><td> </td>
04-30 12:19:12.362: INFO/GET RESPONSE(256): </tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr><td colspan="9"><a href="/bs.exe?RI=0&SID=5FC39">Fahrtbegleiter</a> </td></tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr><td colspan="9"><hr></td></tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <td> </td><td> <img src="http://www.busspur.de/logos/efa-bus.gif" title="Niederflurbus"></td><td>12:26</td><td title="lc0">Aachen, Kaiserplatz [Heinrichsalle Ri. Hansemannplatz] <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_kaiserplatz.pdf">Umgebungsplan</a></td><td>22</td><td title="lc0">Aachen, Karlsgraben <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_karlsgraben.pdf">Umgebungsplan</a></td><td>12:37</td><td>00:11 / Â 1,00</td><td> </td>
04-30 12:19:12.362: INFO/GET RESPONSE(256): </tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr><td colspan="9"><a href="/bs.exe?RI=1&SID=5FC39">Fahrtbegleiter</a> </td></tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr><td colspan="9"><hr></td></tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <td> </td><td> <img src="http://www.busspur.de/logos/efa-bus.gif" title="Niederflurbus"></td><td>12:28</td><td title="lc0">Aachen, Kaiserplatz [Heinrichsalle Ri. Hansemannplatz] <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_kaiserplatz.pdf">Umgebungsplan</a></td><td>25</td><td title="lc0">Aachen, Karlsgraben <a href="http://download.avv.de/Umgebungsplaene/hlp_ac_karlsgraben.pdf">Umgebungsplan</a></td><td>12:39</td><td>00:11 / Â 1,00</td><td> </td>
04-30 12:19:12.362: INFO/GET RESPONSE(256): </tr>
04-30 12:19:12.362: INFO/GET RESPONSE(256): <tr><td colspan="9"><a href="/bs.exe?RI=2&SID=5FC39">Fahrtbegl