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

前端 未结 2 470
南笙
南笙 2021-02-12 22:38

I need to use special characters for stringentity as below.

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost         


        
相关标签:
2条回答
  • 2021-02-12 22:56

    Change to:

        HttpEntity entity = new StringEntity("test®", "UTF-8"); 
    
    0 讨论(0)
  • 2021-02-12 23:10

    Instead of using StringEntity I've just used ByteArrayEntity and it worked:

    String string = "ã@í";
    HttpEntity httpEntity = new ByteArrayEntity(string.getBytes("UTF-8"));
    request.addHeader("Content-type", "application/xml;charset=UTF-8");
    request.setEntity(httpEntity);
    
    0 讨论(0)
提交回复
热议问题