关于HttpClient的中文参数编码问题

Posted on

关于HttpClient的中文参数编码问题 - 讨论区 - 开源中国社区

当前访客身份:游客 [ 登录 | 加入开源中国 ]

当前位置:讨论区 » 技术分享 » HttpComponents

软件 代码 讨论区 新闻 博客 红薯

关于HttpClient的中文参数编码问题

红薯 发表于 10-5 17:13 3年前, 1回/762阅, 最后回答: 4个月前 讨论区 » 技术分享

开源扑克第二轮预售,截止时间 9 月 30 日 我要购买 今天在使用HttpClient提交中文参数的时候发现服务器不管怎么处理得到的字符串都是乱码,考虑应该是客户端的问题,查阅 HttpClient的文档,提到这么一段:

The standard for URLs ( RFC1738 ) explictly states that URLs may only contain graphic printable characters of the US-ASCII coded character set and is defined in terms of octets. The octets 80-FF hexadecimal are not used in US-ASCII and the octets OO-1F hexadecimal represent control characters; characters in these ranges must be encoded. Characters which cannot be represented by an 8-bit ASCII code, can not be used in an URL as there is no way to reliably encode them (the encoding scheme for URLs is based off of octets). Despite this, some servers do support varying means of encoding double byte characters in URLs, the most common technique seems to be to use UTF-8 encoding and encode each octet separately even if a pair of octets represents one character. This however, is not specified by the standard and is highly prone to error, so it is recommended that URLs be restricted to the 8-bit ASCII range. 因此在提交中文参数的时候必须进行转码: NameValuePair content = new NameValuePair("content",new String(" 你好中国".getBytes(),"8859_1")); 搞定!

标签: HttpComponents HttpClient 补充话题说明»

分享到 **

收藏 **

1 **

举报 **

0 | 0 **

按默认排序 | 显示最新评论 | 回页面顶部 共有1个评论 发表评论»

  • hujiong

hujiong 回答于 2012-05-08 09:25

举报 有帮助(0) | 没帮助(0) | 评论(0) | 引用此评论

非会员用户) ")")") 回评论顶部 | 回页面顶部 有什么技术问题吗? 我要提问

全部(4766)...红薯的其他问题

© 开源中国社区(OsChina.NET) | 关于我们 | 广告联系 | @新浪微博 | 开源中国手机版 | 粤ICP备12009483号-3

希望本站内容对您有点用处,有什么疑问或建议请在后面留言评论
转载请注明作者(RobinChia)和出处 It so life ,请勿用于任何商业用途