php urlencode vs java URLEncoder.encode
结论:urlencode 先比URLEncoder.encode多编码 “ * ” 符号,其他都保持一致
php urlencode
phpversion()>=5.3 will compliant with RFC 3986, while phpversion()<=5.2.7RC1 is not compliant with RFC 3986.
参考 RFC3896 方式编码
返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+)。
此编码与 WWW 表单 POST 数据的编码方式是一样的,同时与 application/x-www-form-urlencoded 的媒体类型编码方式一样。
由于历史原因,此编码在将空格编码为加号(+)方面与 » RFC3896 编码(参见 rawurlencode())不同。
php并没有完全按照 rfc3896编码,符号【~】在标准中是不用编码,但是他也编码了。
所以最终的未编码的字符列表为 [-], [_], [.],如同其文档中描述的一样
java URLEncoder.encode
参考 RFC2396 方式编码
但是由于ie浏览器编码了除 "-", "_", ".", "*" 之外的字符,java采用了和IE一样的编码列表,
所以最终的未编码的字符列表为 [-], [_], [.], [*]
The list of characters that are not encoded has been
determined as follows: RFC states:
-----
Data characters that are allowed in a URI but do not have a
reserved purpose are called unreserved. These include upper
and lower case letters, decimal digits, and a limited set of
punctuation marks and symbols. unreserved = alphanum | mark mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" Unreserved characters can be escaped without changing the
semantics of the URI, but this should not be done unless the
URI is being used in a context that does not allow the
unescaped character to appear.
----- It appears that both Netscape and Internet Explorer escape
all special characters from this list with the exception
of "-", "_", ".", "*". While it is not clear why they are
escaping the other characters, perhaps it is safest to
assume that there might be contexts in which the others
are unsafe if not escaped. Therefore, we will use the same
list. It is also noteworthy that this is consistent with
O'Reilly's "HTML: The Definitive Guide" (page ). As a last note, Intenet Explorer does not encode the "@"
character which is clearly not unreserved according to the
RFC. We are being consistent with the RFC in this matter,
as is Netscape.
History of related RFCs:
RFC 1738 section 2.2
only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.
RFC 2396 section 2.3
unreserved = alphanum | mark
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
RFC 2732 section 3
(3) Add "[" and "]" to the set of 'reserved' characters:
RFC 3986 section 2.3
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
RFC 3987 section 2.2
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
php urlencode vs java URLEncoder.encode的更多相关文章
- java URLEncoder 和Base64.encode()
参考: http://www.360doc.com/content/10/1103/12/1485725_66213001.shtml (URLEncode) http://blog.csdn.net ...
- 关于 web中 使用 java.net.URLEncoder.encode 要编码两次呢 , js的encodeURIComponent 同理
因为在jsp中对中文进行了编码的时候用的是UTF-8的编码方式,而在servlet中调用request.getParameter();方法的时候使用服务器指定的原始编码格式(ISO-8859-1)自动 ...
- java中的URLEncoder.encode对应JS中用decodeURIComponent,js和java编码,解码
用get请求传中文,经常搞到乱码,这几天搞搞这个东西,总结一下,以方便以后处理这类的问题. Java代码中的URLEncoder.encode方法和JS的encodeURIComponent功能差不多 ...
- 为什么java的web开发中URLEncoder.encode方法要为什么要调用两次
一: 我们先看2个编码的情况 String name=java.net.URLEncoder.encode("测试", "UTF-8"); System.out ...
- 中文乱码在java中URLEncoder.encode方法要调用两次解决
中文乱码在java中URLEncoder.encode方法要调用两次解决 一.场景: 1.我在客户端要通过get方式调用服务器端的url,将中文参数做utf-8编码,需要在js中两次的进行编码,服务器 ...
- 如何判断某String是否经过urlEncoder.encode过
import java.util.BitSet; public class UrlEncoderUtils { private static BitSet dontNeedEncoding; stat ...
- URLEncoder.encode问题
遇到java里的URLEncoder.encode方法编码后与javascript的encodeURIComponent方法的结果有点不一样,找了一下资料,原来URLEncoder实现的是HTML形式 ...
- URLEncoder.encode 和 URLDecoder.decode 处理url的特殊参数
在使用 url 的 queryString 传递参数时,因为参数的值,被DES加密了,而加密得到的是 Base64的编码字符串,类似于: za4T8MHB/6mhmYgXB7IntyyOUL7Cl++ ...
- Java——URLEncoder和URLDecoder
import java.net.URLDecoder; import java.net.URLEncoder; //========================================== ...
随机推荐
- day 58 bootstrap part2
bootstrap组件的官网, https://v3.bootcss.com/components/#page-header 在bootstrap里面出了HTML和css样式之外还有很多的辅助工具,我 ...
- INSERT 中ON DUPLICATE KEY UPDATE的使用
如果您指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则执行旧行UPDATE.例如,如果列a被定义为UNIQUE,并 ...
- Double.parseDouble(String s)
要把字符串转换为Double类型,只能转换“0.02”这种格式的字符串,不能转换百分比格式的,比如“2%” 这个时候可以Double cbl= Double.parseDouble(“2%”.repl ...
- 最小生成树-QS Network(Prim)
题目大意: 给出的案例结果得出步骤,如下图所示,从结点1开始查找,找出的一条路径如绿色部分所标注.(关键处在于连接每条路径所需要的适配器的价格得加上去) 代码实现: #include<iostr ...
- 一、网络编程-UDP传输协议及socket套接字使用
知识点基本介绍:1.网络通信协议一般就是UDP和TCP俩种传输协议,这一章先说UDP,UDP是一种比较简单的传输协议,如qq使用的就是UDP 2.ip:ip就是标记网络中中的一台电脑 ...
- Django 学习第八天——Django模型基础第三节
一.表关系的实现: 一对一:OneToOne(外键+唯一键) xxx = models.OneToOneField('关联的表',on_delete=models.CASCADE) 外键和一对一关系的 ...
- codeforces723----C. Polycarp at the Radio
//AC代码...表示很晕 #include <iostream> using namespace std; ],b[]; int main() { int n,m,cnt; cin &g ...
- BZOJ.3551.[ONTAK2010]Peaks加强版(Kruskal重构树 主席树)
题目链接 \(Description\) 有n个座山,其高度为hi.有m条带权双向边连接某些山.多次询问,每次询问从v出发 只经过边权<=x的边 所能到达的山中,第K高的是多少. 强制在线. \ ...
- 洛谷P2569 股票交易
题目传送门https://www.luogu.org/problemnew/show/P2569 第一眼看题就觉得是个dp ,然后看到2000的范围,hmm大概是个n^2的2维dp 开始设状态,第一维 ...
- Java并发编程(八)-- 死锁
简介 当两个以上的运算单元,双方都在等待对方停止运行,以获取系统资源,但是没有一方提前退出时,就称为死锁.在多任务操作系统中,操作系统为了协调不同进程,能否获取系统资源时,为了让系统运作,必须要解决这 ...