Pessoal, estou tendo problema com codificação de caracteres ao passar uma URL pro httpclient, tentei usar o metodo encode() da classe URLEncoder mas não tá funcionando. Onde eu tô errando ali?
[code] public static String getRetornoServidor(String url) {
String Rst;
try {
HttpClient httpclient = new DefaultHttpClient();
url = URLEncoder.encode(url, "ISO-8859-1");
url = url.replace("+", "%20");
url = url.replace(" ", "%20");
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
Rst = reader.readLine();
is.close();
} catch (ClientProtocolException e) {
Rst = null;
} catch (IOException e) {
Rst = null;
} catch (Exception e) {
Rst = null;
}
if (Rst != null) {
Rst = Rst.trim();
}
return Rst;
}[/code]
PS: Tentei tanto ISO-8859-1 quanto UTF-8 também, mas não funcionou. Alguém já teve esse problema?
Abraços.