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

前端 未结 2 466
南笙
南笙 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 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);
    

提交回复
热议问题