当前位置:网站首页>关于url编解码应该选用的函数
关于url编解码应该选用的函数
2022-07-27 00:14:00 【Wuuconix】
关于url编解码应该选用的函数
先给出所有的函数
- escape
- unescape
- encodeURI
- decodeURI
- encodeURIComponent
- decodeURIComponent
其中第一组已经被废弃了。因为它不支持unicode的编解码。

可以看到escape对于中文无法获得正确的url编码。
至于 encodeURI 和 encodeURIComponent之间的差别,前者适用于编码整个形成整个URI,而后者适合编码局部,比如search部分。

可以看到encodeURI能够获得一个非常正常的可以访问的URI链接。
而encodeURIComponent对于同样的参数的结果如下。

可以看到,它把正常URI链接里面的 /和#等字符也给编码了,这就导致得到的字符串不再是一个合法的URI链接。
所以encodeURIComponent适合于编码 search部分。比如这样的情景。

这里模拟了file字段里有#和/这样的特殊字符,如果用encodeURI就无法正常编码了,因为它会跳过,而encodeURIComponent则可以完成这一任务。

对于前端来说,一个项目肯定是有一个baseURI的,比如部署在 url.wuuconix.link 。这时候一般来说处理的时候就是往这个baseURI后面加上一个写段,即search。所以encodeURIComponent的使用频率会更大一些。
边栏推荐
- 什么是进程?
- Functions of libraries and Archives
- GoatGui邀你参加机器学习研讨班
- Web3.0世界知识体系分享-什么是Web3.0
- Interview shock 68: why does TCP need three handshakes?
- swiperjs自定义宽度
- com.fasterxml.jackson.databind.exc.InvalidDefinitionException
- Static keyword
- Database knowledge required by testers: MySQL common syntax
- Ansible series: do not collect host information gather_ facts: False
猜你喜欢

c语言:深度学习递归

LabVIEW中编程更改进程的优先级

Arduinouno drive RGB module full color effect example

数据库读写分离和分库分表

Time module: acquisition and mutual transformation of timestamp, structured time and formatted time

用swiper分类图标

C language program compilation

Web3.0世界知识体系分享-什么是Web3.0

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

Cloud development sleeping alarm clock wechat applet source code
随机推荐
[NISACTF 2022]上
MySQL 5.7 takes the first item of the group
FormData的使用
次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
基于GoLang实现API短信网关
系统安全测试要怎么做,详细来说说
【Redis】五种常用的数据类型
Time module: acquisition and mutual transformation of timestamp, structured time and formatted time
杀毒软件 clamav 的安装和使用
Function stack frame explanation
从ACL 2022 Onsite经历看NLP热点
LabVIEW中编程更改进程的优先级
什么是进程?
次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
bp 插件临时代码记录
Leetcode skimming -- no.238 -- product of arrays other than itself
快速排序(Quick sort)
Database read-write separation and database and table segmentation
调用JShaman的Web API接口,实现JS代码加密。
万字长文,带你搞懂 Kubernetes 网络模型