带有 ® 等特殊字符的 StringEntity HttpPost,看到的是 ¿½` 而不是 ® [英] HttpPost with StringEntity having special characters like ®, seeing ¿½` instead of ®

查看:19
本文介绍了带有 ® 等特殊字符的 StringEntity HttpPost,看到的是 ¿½` 而不是 ®的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 stringentity 使用特殊字符,如下所示.

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();

输出在响应中包含 test� 而不是 test®.

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

推荐答案

更改为:

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

这篇关于带有 ® 等特殊字符的 StringEntity HttpPost,看到的是 ¿½` 而不是 ®的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆