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"); 
乱码就好了
posted on 2014-04-30 16:45  狂奔的冬瓜  阅读(1174)  评论(0编辑  收藏  举报