HttpPost with StringEntity with special characters like ®, seeing ¿½` instead of ®

I need to use special characters for stringentity like stringentity below.

 DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpEntity entity = new StringEntity("test®"); httpPost.setEntity(entity); httpPost.setHeader("Accept-Encoding", "UTF-8"); HttpResponse response = httpClient.execute(httpPost); BufferedReader reader = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); while ((reader.readLine()) != null) { System.out.println (reader.readLine()); } reader.close(); 

The output contains test� instead of test® in the answer.

+10
java character-encoding
source share
2 answers

Change to:

  HttpEntity entity = new StringEntity("test®", "UTF-8"); 
+21
source

Thanks, this worked for me due to non-English characters, which made me worry for 3 days, I added the code "UTF-8" to httppost.setEntity (new StringEntity (entityString, "UTF-8" ));

0
source

All Articles