Listnvpl = new ArrayList ();nvpl.add(new BasicNameValuePair("Province","福建省"));nvpl.add(new BasicNameValuePair("City","福州市"));nvpl.add(new BasicNameValuePair("Content","也可以"));
几种方式编码:
dedFormEntity s1 = new UrlEncodedFormEntity(nvpl,"gb2312");UrlEncodedFormEntity s2 = new UrlEncodedFormEntity(nvpl,"utf-8");UrlEncodedFormEntity s3 = new UrlEncodedFormEntity(nvpl,"GBK");System.out.println(EntityUtils.toString(s1));System.out.println(EntityUtils.toString(s2));System.out.println(EntityUtils.toString(s3));
和firebug的post参数比较发现它用的gb2312提交的,故:
httpost.setEntity(new UrlEncodedFormEntity(nvpl,"utf-8"));
改成
httpost.setEntity(new UrlEncodedFormEntity(nvpl,"gb2312"));问题解决。 url的编码和解码: URLDecoder.decode("%B8%A3%D6%DD%CA%D0", "gb2312") encode 另外注意URLEncodedUtils类