I am trying to send a message (containing both English and Chinese) to a servlet. if I use a Java application to post a post, it works well.
public class PostText { public final static String HTTP_PORT = "..."; public static void main(String[] args) throws Exception { String message = "..."; System.out.println(post(message)); } public static String post(String message) { HttpPost httpRequest = new HttpPost(HTTP_PORT); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("input", message)); try { httpRequest.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); org.apache.http.HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == 200) { String strResult = EntityUtils.toString(httpResponse.getEntity()); return strResult; } else { System.out.println(httpResponse.getStatusLine().getStatusCode()); } } catch (ClientProtocolException e) {
As long as I use HttpPost on Android, the server will receive unrecognized characters, for example "æ¸Γ₯Γ₯€§Γ₯ |". And I tried using HttpURLConnection to post a message, the result also contains unrecognized characters. What is the difference between HttpClient in a Java application and HttpClient in an Android application? It is very strange.
Thank you very much.
source share