Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I need to use special characters for stringentity as 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 response.

like image 517
java techie Avatar asked Dec 09 '13 15:12

java techie


1 Answers

Change to:

    HttpEntity entity = new StringEntity("test®", "UTF-8");  
like image 58
Italo Borssatto Avatar answered Oct 02 '22 23:10

Italo Borssatto