1. 程式人生 > >HttpUrlConnection post方法傳遞中文亂碼問題

HttpUrlConnection post方法傳遞中文亂碼問題

這個方法  仍然要拼接訊息體

裡面的引數若不用URLEncoder.encode  對其進行編碼 logcat會出現

04-30 08:39:15.480: W/System.err(2635): java.io.IOException: Content-Length exceeded  這個錯誤。

但是隻對引數進行序列化

不對這個HttpUrlConnection 物件的訊息頭設定編碼格式  伺服器接受的訊息仍然是亂碼的。

conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");  //我嘗試了 獨立的新增下面的 仍然是亂碼

   httpurlconnection.setRequestProperty("Accept-Charset", "utf-8");
   httpurlconnection.setRequestProperty("contentType", "utf-8");

後來調整為
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); 
亂碼就好了