Android到HTTP中文亂碼解決
android端發送:
String params = "aaa=" + URLEncoder.encode(aaa, "utf-8")
+ "&bbb=" + bbb+ "&ccc="
+ ccc;
byte[] entity = params.getBytes();
String path = "http://192.168.1.100:8080/myhttp/servlet/ListAction";
HttpURLConnection conn = (HttpURLConnection) new URL(path)
.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length",
String.valueOf(entity.length));
conn.getOutputStream().write(entity);
服務端:
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String aaa= request.getParameter("aaa");
String bbb= request.getParameter("bbb");
String ccc= request.getParameter("ccc");
System.out.println("aaa="+aaa);
System.out.println("bbb="+bbb);
System.out.println("ccc="+ccc);
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11