问题
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();
The output contains test�
instead of test®
in the response.
回答1:
Change to:
HttpEntity entity = new StringEntity("test®", "UTF-8");
来源:https://stackoverflow.com/questions/20473848/httppost-with-stringentity-having-special-characters-like-seeing-%c2%bd-instead