encodeURI没有逃脱`equals` - 为什么?

Max*_*kyi 2 javascript http

我有一个这样的URI:

http://client.dev/dap/module/hdfs-web/api/v1.0/clusters/Cluster%201%20-%20CDH4?operation=copy&to=/user/hdfs/year=2016/partial.txt&overwrite=true
Run Code Online (Sandbox Code Playgroud)

我用encodeURI函数来转义字符串.我想知道为什么空格被编码%20equals字符不是?

phi*_*hag 5

encodeURI编码完整的URI,URI可以包含=字符.例如,如果用户输入URI,解决它的第一步就是调用encodeURI它.

另一方面,如果您构建URI,并且输入只确定一个字段(例如,搜索查询,当E=mc²您想要解析时https://www.google.com/search?q=E%3Dmc%C2%B2),那么您不是编码完整URI,而是编码URI 组件.使用encodeURIComponent为:

> encodeURIComponent('= ')
'%3D%20'
Run Code Online (Sandbox Code Playgroud)