关于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 **
举报 **
按默认排序 | 显示最新评论 | 回页面顶部 共有1个评论 发表评论»
hujiong 回答于 2012-05-08 09:25
举报 有帮助(0) | 没帮助(0) | 评论(0) | 引用此评论
) ")")") 回评论顶部 | 回页面顶部 有什么技术问题吗? 我要提问
全部(4766)...红薯的其他问题
- OSChina 用户动态设计说明(2回/241阅,26分钟前)
- 提取 SQL Server 的日志信息并发送邮件(0回/71阅,3天前)
- OSChina 的留言表设计说明(59回/5932阅,3天前)
- 遠端管理 VirtualBox 的神兵利器-RemoteBox(0回/70阅,4天前)
在 Node.js 上运行 Perl 脚本(0回/75阅,5天前) 类似的话题
HttpClient 爬数据时 中文编码问题(2回/1351阅,2年前)
- HTTPClient PostMethod 中文乱码问题解决方法(1回/382阅,9个月前)
- 应用HttpClient来对付各种顽固的WEB服务器(2回/1389阅,3年前)
- httpClient 4.x中,MultipartEntity中附加中文信息时的乱码解决(1回/566阅,9个月前)
- Android 使用 httpClient 取消http请求的方法(0回/411阅,9个月前)
- 使用 Apache HttpClient 突破 J2EE 站点认证(0回/361阅,3年前)
- 为 Android 开发访问 JAX-RS Web 服务的 Apache HttpClient 客户端(3回/714阅,10个月前)
- 使用 HttpClient 和 HtmlParser 实现简易爬虫(3回/2861阅,3年前)
- Android 与 HttpClient 通讯出现乱码问题的解决(0回/223阅,10个月前)
- Apache HttpClient Cookie rejected 解决方法(1回/279阅,9个月前)
- 豆瓣API求帮助(0回/245阅,1年前)
- 怎么自动注册一个账户,类似yahoo.com(18回/883阅,2年前)
- Android Http异步请求,Callback(0回/650阅,9个月前)
- Android中的几种网络请求方式详解(0回/1424阅,8个月前)
- 打造一款 Android 联网 tic-tac-toe 游戏(4回/709阅,11个月前)
- HttpClient, 使用C/#操作Web(0回/35阅,9个月前)
© 开源中国社区(OsChina.NET) | 关于我们 | 广告联系 | @新浪微博 | 开源中国手机版 | 粤ICP备12009483号-3