URL httpclient acentuação e caracteres especiais

0 respostas
L

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?

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;
	}

PS: Tentei tanto ISO-8859-1 quanto UTF-8 também, mas não funcionou. Alguém já teve esse problema?

Abraços.

Criado 11 de novembro de 2013
Respostas 0
Participantes 1