httpclient提交的时候根据firebug的post数据猜下它的编码方式,对某个字段编码比较下。
form提交的参数:
List<NameValuePair> nvpl = new ArrayList<NameValuePair>();
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));
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类