我需要为 stringentity
使用特殊字符,如下所示。
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®
。
最佳答案
更改为:
HttpEntity entity = new StringEntity("test®", "UTF-8");
关于java - 带有 StringEntity 的 HttpPost 具有特殊字符,如 ®,看到 ¿½` 而不是 ®,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20473848/