Ultimate Get/Post with Android Thread for Dummies
Posted
by Jayomat
on Stack Overflow
See other posts from Stack Overflow
or by Jayomat
Published on 2010-04-30T01:14:23Z
Indexed on
2010/04/30
1:17 UTC
Read the original article
Hit count: 412
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);
One person also gave me a hint to use firebug to read what's going on at the page, but I don't really understand what to look for, or more precisely, how to use the provided information.
I also find it confusing, for example, that when I enter the data by hand, the url says, for example, "....HTO=Kaiserplatz&...", but in Firebug, the same Kaiserplatz is connected to a different field, in this case:
\<\td class="Start3"> Kaiserplatz <\/td> (I inserted \ to make it visible)
The last line in my code prints the html page, but without having send a request.. it's printed as if there was no input at all...
My app is almost done, I hope someone can help me out to finish it!
thanks in advance
© Stack Overflow or respective owner