I need my program to send a request to a server. The problem is, the server only recognizes ös,äs und üs, but JAVA and/or Android don’t know them. `How can I send a request with a String like “Hermann-Löns” without JAVA/Android “changing” the ö…. Oh and btw., “oe” isn’t recognized by the server too, already tried that…
thx for help!
@BalausC:
I changed your code to:
I’m not sure if this is how you refer to the right fields…
String url = "http://busspur02.aseag.de/bs.exe?SID=473A2&ScreenX=1440&ScreenY=900&CMD=CR&DatumT=30&DatumM=4&DatumJ=2010&AbfAnk=Abf&ZeitH=10&ZeitM=45&Intervall=60&Loeschen=%28N%29eue+Suche";
String charset = "CP1252";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("HTO", start_from));
params.add(new BasicNameValuePair("HT1", destination));
UrlEncodedFormEntity query = new UrlEncodedFormEntity(params, charset);
HttpPost post = new HttpPost(url);
post.setEntity(query);
InputStream response = new DefaultHttpClient().execute(post).getContent();
// Now do your thing with the facebook response.
I can’t compile because I get an error saying:
The method getContent() is undefined
for the type HttpResponse
If I delete getContent() is says:
Type mismatch: cannot convert from HttpResponse to InputStream
One more thing: I use htmlparser (http://htmlparser.sourceforge.net/) to parse the resulting website. How do I access the resulting html site to parse it? Because otherwise I would have to rewrite nearly all of my code to get the results..
To the point, you need to use
java.net.URLEncoderwith the appropriate character encoding to encode the special characters in request parameters.Ensure that you specify an
Accept-Charset: CP1252header in the HTTP request. For a more complete code example how to fire a HTTP request with correct encoding, check this answer which I posted a hour ago. It also covers a HttpClient example which is also included in Android.