java.lang.IllegalArgumentException: Illegal character in scheme at index 0
2015-06-05 23:34
721 查看
有时候,通过httplicent发送url的时候,你会遇到懊恼的java.lang.IllegalArgumentException: Illegal character in scheme at index 0。
你会看到 空格被转成了+号了。
When to encode space to plus (+) or %20 ...
google 上有解释:
This behaves as expected. The
From the
javadocs:
This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format.
and from the
HTML Specification:
application/x-www-form-urlencoded
Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by `+'
You will have to replace it, e.g.:
https://www.gotosearch.info/?gws_rd=cr#safe=strict&q=why+urlencoder+change+the+space+to+a+%2B
作为程序员。你做好用google,百度的话,估计找半天找不到一个好答案,google,一般答案就在那里了。
你会看到 空格被转成了+号了。
When to encode space to plus (+) or %20 ...
google 上有解释:
URLEncoder not able to translate space character
52 down vote favorite 8 | I am expectingSystem.out.println(java.net.URLEncoder.encode("Hello World", "UTF-8")); to output: Hello%20World (20 is ASCII Hex code for space) However, what I get is: Hello+World Am I using the wrong method? What is the correct method I should be using? |
URLEncoderimplements the HTML Specifications for how to encode URLs in HTML forms.
From the
javadocs:
This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format.
and from the
HTML Specification:
application/x-www-form-urlencoded
Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by `+'
You will have to replace it, e.g.:
System.out.println(java.net.URLEncoder.encode("Hello World", "UTF-8").replace("+", "%20"));
https://www.gotosearch.info/?gws_rd=cr#safe=strict&q=why+urlencoder+change+the+space+to+a+%2B
作为程序员。你做好用google,百度的话,估计找半天找不到一个好答案,google,一般答案就在那里了。
相关文章推荐
- Firefox下提示illegal character并出现乱码的原因
- Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
- GP数据库笔记--数据类型转换,杀掉进程的方法
- GP数据库关于行列转换
- 查看修改mysql编码方式
- Linux上删除空行的方法
- Python错误: SyntaxError: Non-ASCII character eclipse pydev 下
- sybase字符集配置与转化
- 【android错误】bitmap size exceeds 32bits
- illegal interface qualifier
- air max wright "
- T-sql函数
- Symbian 基本类型转换
- You will surely observe a Tiffany jewelry
- JS中URL传中文参数引发的乱码问题
- 编译原理—词法分析器
- 转oracle字符集
- How to Hack Runescape
- C语言宏高级用法 [总结]