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类
本文深入探讨了在使用HTTP客户端提交表单数据时,如何根据Firebug捕获的POST数据来确定其编码方式,并通过实例演示了不同编码方式下数据的输出效果。同时,文章还介绍了URL编码和解码的基本概念,以及如何使用相关工具进行操作。最后,文章通过对比实际编码方式,调整HTTP请求参数的编码设置,成功解决了数据传输过程中出现的问题。

1587

被折叠的 条评论
为什么被折叠?



