Hi,

I'm having problems in get some UTF-8 characters, like 'ç','á' and
etc...
To be sure that the problem is in the http, I made few tests:
- Using a textView, I'm able to use these characters;
- If I open the link via Browser(firefox), I'm also able to see the
special characters;
- In the debug mode, when I receive the data from the server, if I
modify the value of the string that is having problems using the
eclipse debuging mode, I'm also able to see it correctly.

So, I really think that the problem is in the connection. I tried a
lot of combination and is not working.
These is the http code:
Code:

public class Http {

    public String getUrlData(String url) {
        String websiteData = null;
        DefaultHttpClient client = new DefaultHttpClient();
        try {
            HttpGet method = new HttpGet(new URI(url));
            HttpParams httpparams = new BasicHttpParams();
            HttpProtocolParams.setVersion(httpparams,
HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(httpparams, "UTF-8");
            method.setParams(httpparams);
            method.addHeader("Accept", "*/*");
            HttpResponse res = client.execute(method);
            websiteData = getResponse(res.getEntity());
        } catch (IOException e) {
            Log.e( "ouch", "!!! IOException " + e.getMessage() );
        } catch (URISyntaxException e) {
            Log.e( "ouch", "!!! IOException " + e.getMessage() );
        }
        return websiteData;
    }

    private String getResponse( HttpEntity entity )
    {
        String response = "";
        try
        {
            int length = ( int ) entity.getContentLength();
            StringBuffer sb = new StringBuffer( length );
            InputStreamReader isr = new
InputStreamReader( entity.getContent(), "UTF-8" );
            char buff[] = new char[length];
            int cnt;
            while ( ( cnt = isr.read( buff, 0, length - 1 ) ) > 0 )
            {
                        sb.append( buff, 0, cnt ); //Here the
character is alredy wrong.
            }
            response = sb.toString();
            isr.close();
        } catch ( IOException ioe ) {
            ioe.printStackTrace();
        }
        return response;
    }
}

You will probably notice that is liek any example on the internet. The
only thing is that I tried to add UTF-8 in any place that is possible
to receive it.

Thanks for your help!

Joao

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to