具有StringEntity的HttpPost具有特殊字符(如®),而不是®看到½ [英] HttpPost with StringEntity having special characters like ®, seeing ¿½` instead of ®
本文介绍了具有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屋!
查看全文