转帖知识点
使用android手机,在使用post请求传递中文内容向服务器端时,如果服务器端要求使用utf-8的编码格式时需要对post请求数据做以下处理;
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4);
nameValuePair.add(new BasicNameValuePair(“get_uid”,
get_uid));
nameValuePair.add(new BasicNameValuePair(“message”,
message));
nameValuePair.add(new BasicNameValuePair(“calendarlist[pageindex]“,
pageindex));
nameValuePair.add(new BasicNameValuePair(“calendarlist[recordlimit]“,
recordlimit));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair,”UTF-8″));
这里的message字段是含有中文的;而一般的字符转换方法如:new String(message.getBytes(), “UTF-8 “);这样转换,是不成功的;
这里需要用到的方法就是new UrlEncodedFormEntity(nameValuePair,”UTF-8″);
转载本站文章请注明,转载自:阿达基站路测的天空[http://blog.signalsitemap.com]