• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

issue with org.apache.http.client.HttpClient

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
i am trying to use httpclient to get content from a url which returns me xml.
it is working properly for english but for Thai or Chinese character i am getting message like <Text>นามสกุล</Text>
instead of proper Thaicharacters.
i tried to set encoding like
httpclient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
but it is not working.

please provide necessary help.

thanks
Amitosh
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Character encoding problems can be confusing to solve, because the problem can be in one of many places. For example, it could be at the point where you read the data and convert it to characters, or at the point where you display the data.

Check every step of the process, from receiving to displaying the data, and make sure you're aware of what character encoding is used at each step.

How are you displaying the data? Note that the Windows command prompt can't deal properly with different character encodings, so if you print stuff with System.out.println() you might see strange characters instead of the Thai letters you expect.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It appears that you're trying to download XML using HttpClient. Remember that the encoding you should use to interpret the data in the response is the encoding of the HTTP response and not the encoding declared in the XML document. So defaulting the encoding to UTF-8 might be the wrong thing to do. When I encountered this sort of problem my fix was to find the encoding used in the response -- there's a method in HttpClient which allows you to do that.
 
Amitosh Mishra
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for your help.

i resolved the issue by using

HttpResponse response = client.execute(httpget);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity,"UTF-8");

regards
Amitosh

 
reply
    Bookmark Topic Watch Topic
  • New Topic