Murat
Murat

Reputation: 3294

How to set character encoding of httpclient

I am using this httpclient: http://loopj.com/android-async-http/ I am getting a json with this httpclient. I want to set character enconding of this httpclient. The JSONObject that the client returns contains turkish chars such as şğöü. But it is corrupted and i cant view this characters.

How can i set character encoding of this httpclient?

Upvotes: 1

Views: 5024

Answers (2)

Yasir Ali
Yasir Ali

Reputation: 1804

i resolved this problem by modifying the loopj source code file "AsyncHttpResponseHandler.java"...

void sendResponseMessage(HttpResponse response){
      .........
      //responseBody = EntityUtils.toString(entity, "UTF-8");
        responseBody = EntityUtils.toString(entity, "ISO-8859-1");
}

ISO-8859-1 encoding will give you the correct characters..

Upvotes: 0

lujop
lujop

Reputation: 13893

The correct would be that server provides the encoding of the returned page. If it does that you will receive the correct one. But if it doesn't provides the encoding Async-http seems to assume UTF-8 and looking at the code it doesn't seems to support providing a default alternative one.

Relevant code in AsyncHttpResponseHandler :

// Interface to AsyncHttpRequest
void sendResponseMessage(HttpResponse response) {
    ...
    responseBody = EntityUtils.toString(entity, "UTF-8");

If you want to do you will need to user your own version of AsyncHttpResponseHandler or suggest a patch to be able to specify default encoding.

Upvotes: 5

Related Questions